gpt4 book ai didi

android - 如何在 Android 中最小化 Activity 时关闭 GPS?

转载 作者:行者123 更新时间:2023-11-30 03:06:35 25 4
gpt4 key购买 nike

public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
Context context = getActivity();
String provider = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (provider.contains("gps")){
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
}
}
return super.onKeyDown(keyCode, event);
}

我做了一些代码,但它不能禁用 GPS。如果您有代码请分享,我希望在应用程序最小化或关闭时关闭 GPS,当应用程序启动时它会自动打开 GPS,我打开了它但无法关闭..

最佳答案

启用和禁用 GPS 掌握在用户手中。您可以向他显示一个对话框,通知他有关禁用 GPS 的信息。在这种情况下,在对话框上保留两个按钮 - 一个用于“设置”,另一个用于“确定”或“取消”。
像这样的东西:

public static void promptForGPS(
final Activity activity)
{
final AlertDialog.Builder builder =
new AlertDialog.Builder(activity);
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
final String message = "Disable GPS....Message here"
+ " service to find current location. Click OK to go to"
+ " location services settings to let you do so.";

builder.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
activity.startActivity(new Intent(action));
d.dismiss();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
d.cancel();
}
});
builder.create().show();
}

进一步引用:
Android activate gps with AlertDialog: how to wait for the user to take action?

关于android - 如何在 Android 中最小化 Activity 时关闭 GPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21721044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com