Is it possible to turn on LocationProviders(GPS Provider/Network Providers) on Device programatically, if it is turned off?
No, it is not, but you can open the Location services settings window:
context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
Enabling Location with mode High Accuracy or Battery saving without user needing to visit Settings
https://android-developers.googleblog.com/2015/03/google-play-services-70-places-everyone.html
private void turnGPSOn(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled
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);
}
}
But this code support only upto APK 8.
Yes but you have to be a Super User (sudo), Your device must be rooted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With