How to set GPS status on when the app is set as Device administrator
by user.
I'm using this method :
private void turnGPSOn() {
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
getApplicationContext().sendBroadcast(intent);
String provider = Settings.Secure.getString(getApplicationContext()
.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"));
this.getApplicationContext().sendBroadcast(poke);
}
}
and getting this error at least on API-21
:
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE from pid=27737, uid=10464
please please please care about Device administrator
permission that is enabled and don't tag the question as duplicated!