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
相关文章推荐
- android 在程序中开启GPS功能
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- Mono For Android 如何控制程序在自动旋转功能开启下不进行横竖屏切换
- 【转载】如何开启Android的虚拟GPS功能
- 【转载】如何开启Android的虚拟GPS功能
- Android用代码实现GPS的开启/关闭功能+网络开关
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- XE5开发Android程序调用电话相关功能(短信息和电话) [转]
- 使用Android开发照相功能小程序实例
- 3.17 MonoForAndroid用户人机界面--关于(About)程序信息 Menu功能菜单程序设计
- android Viewpager禁用/开启滑动切换功能
- Android自动开启GPS
- android4.1去除bluetooth和gps功能
- android 自动开启gps
- Android中如何监听GPS开启和关闭
- android ViewPager 禁用/开启 滑动切换功能