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,我打开它,但不能关闭..如何在Android中将Activity最小化时关闭GPS?