【发布时间】:2015-09-06 04:09:45
【问题描述】:
当应用被用户设置为Device administrator时,如何设置GPS状态。
我正在使用这种方法:
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);
}
}
至少在API-21 上收到此错误:
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE from pid=27737, uid=10464
请注意Device administrator已启用的权限,请勿将问题标记为重复!
【问题讨论】:
-
@Nija:你有没有看过app的状态情况?这是
Device administrator应用程序,所以它比普通应用程序具有更多功能。