【发布时间】:2015-04-08 05:23:50
【问题描述】:
转到设置 -> 位置服务-> 检查对我的位置的访问,我想以编程方式执行此操作 autoEnable ,我尝试了以下代码但无法正常工作
Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
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);
}
}
【问题讨论】:
标签: android android-intent permissions gps location