android设置gps自动开启
来源:互联网 发布:linux新手入门 编辑:程序博客网 时间:2024/06/14 00:21
1.第一种方法
private void toggleGPS() { 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(StartActivity.this, 0, gpsIntent, 0).send(); } catch (CanceledException e) { e.printStackTrace(); }}
2.第二种方法
private void openGPSSettings() { //获取GPS现在的状态(打开或是关闭状态) boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled( getContentResolver(), LocationManager.GPS_PROVIDER ); if(gpsEnabled) {//关闭GPS Settings.Secure.setLocationProviderEnabled( getContentResolver(), LocationManager.GPS_PROVIDER, false ); } else { //打开GPS www.2cto.com Settings.Secure.setLocationProviderEnabled( getContentResolver(), LocationManager.GPS_PROVIDER, true); }
3.第三种方法(手动设置)
LocationManager alm = (LocationManager)StartActivity.this.getSystemService(Context.LOCATION_SERVICE); if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show(); } Toast.makeText(this, "请开启GPS!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS); startActivityForResult(intent,0); //此为设置完成后返回到获取界面
第一第二种需要加上权限
<!--允许程序读取或写入系统设置 -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" ></uses-permission>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
原文:http://www.2cto.com/kf/201206/137623.html
0 0
- android设置gps自动开启
- android设置gps自动开启
- android 自动开启gps
- Android自动开启GPS
- Android GPS 自动开启
- android设置gps开启
- android 调用设置页面开启gps
- android 检查GPS是否开启,GPS设置界面
- 自动开启GPS服务
- android 强制开启 GPS
- Android -开启GPS权限
- Android 判断GPS是否开启
- 【Android】代码开启/关闭GPS
- 【Android】代码开启/关闭GPS .
- Android 判断GPS是否开启
- android GPS开启方法 代码
- android判断GPS是否开启
- android中判断gps是否开启,通过dialog跳转至设置
- c# 操作SQLite
- 查找一个字符串中最大长度的重复子串,例如abcdab 中ab为最大重复字串 长度为2
- ARM linux的启动部分源代码简略分析
- C语言中realloc()使用的说明
- java文件操作之路径的获得
- android设置gps自动开启
- POJ 2699 The Maximum Number of Strong Kings 网络流 竞赛图
- Compiling Vs Transpiling
- openwrt下面创建/添加package----Makefile模版
- Android自定义类似ProgressDialog效果的Dialog
- Content Security Policy
- 第一卷 第一百三十六章 好白菜
- Why does MCP2515 always return to configuration mode?
- 8个超实用的jQuery技巧攻略