Turn on Location Providers Programmatically in Android
No, it is not, but you can open the Location services settings window:
context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
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.
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