我需要以编程方式启用 GPS,以便我使用以下代码启用 GPS:
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);
但是当我使用这段代码时,我得到了以下异常:
01-25 12:11:37.218: W/ActivityManager(477): Permission denied: checkComponentPermission() reqUid=1000
01-25 12:11:37.218: W/ActivityManager(477): Permission Denial: broadcasting Intent { cat=[android.intent.category.ALTERNATIVE] dat=3 cmp=com.android.settings/.widget.SettingsAppWidgetProvider } from com.gpstraking (pid=982, uid=10186) requires null due to receiver com.android.settings/com.android.settings.widget.SettingsAppWidgetProvider
我必须给予什么许可才能避免此异常并启用 GPS。