您的位置:首页 > 移动开发 > Android开发

android 在程序中开启GPS功能

2012-04-27 16:29 330 查看
LocationManager locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);

boolean isEnabled= locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if(!isEnabled){
//这段代码可以实现GPS开关状态的切换
Intent GPSIntent = new Intent();
GPSIntent.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
GPSIntent.setData(Uri.parse("custom:3"));
try {
PendingIntent.getBroadcast(MainActivity.this, 0, GPSIntent, 0).send();
} catch (CanceledException e) {
e.printStackTrace();
}
//				Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, true);


注释掉的代码,表面上看可以简单的实现开启GPS功能,但是运行后发现后没有权限,即使加了权限依旧提示permission denied
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: