jimowuxin 2013-10-14 05:05 采纳率: 0%
浏览 4705

android 如何自动打开GPS

各位大牛,我做了一个应用,需要自动打开GPS,用了网上的方法,不行
[code=java]Settings.Secure.setLocationProviderEnabled(getContentResolver(),LocationManager.GPS_PROVIDER, true);[/code]
这个需要android.permission.WRITE_SECURE_SETTINGS权限 但是这个权限只给系统应用
还有1、
locationManager.setTestProviderEnabled(android.location.LocationManager.GPS_PROVIDER,true);
2、
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(this, 0, GPSIntent, 0).send();
} catch (CanceledException e) {
e.printStackTrace();
}

3、
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.sendBroadcast(intent);
Stringprovider=Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
this.sendBroadcast(poke);
}

以上方法都试了 不行 模拟器是4.0.3的,请各位大牛帮我一把

  • 写回答

1条回答 默认 最新

  • lcuiandlc_8 2013-11-08 08:40
    关注

    因为GPS会有因私问题,所以不能用程序打开,只有引导用户至设置界面让他们手动打开

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀