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

更多相关文章

  1. Android(安卓)5.1 open data flow 数据开启流程
  2. android studio教程 – 快捷键
  3. Android—构建安全的Android客户端请求,避免非法请求
  4. Android使用代码实现RelativeLayout,LinearLayout布局
  5. Android(安卓)下载文件及写入SD卡
  6. Android桌面小部件实例 桌面小时钟
  7. Android(安卓)从代码中打开淘宝和亚马逊、facebook、Message
  8. Creating a ContextMenu on a ListView
  9. android弹出对话框大全

随机推荐

  1. Android(安卓)Applications Tutorial 15.
  2. Android(安卓)拷贝与粘贴
  3. 自定义布局-自定义RelativeLayout
  4. android 制作 ppm开机图
  5. android onLowMemory
  6. ffmpeg无损转h265
  7. Robotium_Automated UI testing for Andr
  8. android 无法安装ApiDemos的问题
  9. Android(安卓)访问外部存储设备 - getExt
  10. Android(安卓)build target list.