I know this is a question that got asked a lot. But all of the answers I could find are very old so I wanted to ask again.
I want to turn off GPS services on the phone programmatically. What is the up to date answer to this ?
Thanks in advance.
I know this is a question that got asked a lot. But all of the answers I could find are very old so I wanted to ask again.
I want to turn off GPS services on the phone programmatically. What is the up to date answer to this ?
Thanks in advance.
Use this code to turn off GPS
String provider = Settings.Secure.getString(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"));
sendBroadcast(poke);
}