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?