android 在程序中开启GPS功能
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
android 在程序中开启GPS功能
猜你喜欢
转载自rongdmmap-126-com.iteye.com/blog/1553389
今日推荐
周排行