【问题标题】:android programmatically Turning on and off GPS in android 4.0 and upandroid 以编程方式在 android 4.0 及更高版本中打开和关闭 GPS
【发布时间】:2014-10-11 21:07:48
【问题描述】:

我想在一个活动中打开和关闭 gps 本地化,尝试每隔一个主题 sugestion,但这是行不通的。 这不是重复的主题,我看所有其他的。

示例:

清单:

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.Manifest.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.Manifest.permission.ACCESS_COARSE_LOCATION" />

活动:

public void turnGPSOn()
 {
 Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
 intent.putExtra("enabled", true);
 this.ctx.sendBroadcast(intent);

String provider = Settings.Secure.getString(activityname.this.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")); 
    activityname.this.sendBroadcast(poke);


}
 }
 // automatic turn off the gps
  public void turnGPSOff()
  {
String provider = Settings.Secure.getString(activityname.this.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){ //if gps is enabled
    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")); 
    activityname.this.sendBroadcast(poke);
  }
 }

当我尝试我的应用程序停止(崩溃)

来源:Turning on and off GPS programmatically in android 4.0 and above?

我不想显示对话框(选择打开本地化)我需要以编程方式完成所有操作(隐藏)

请帮助我。谢谢。

【问题讨论】:

    标签: android gps


    【解决方案1】:

    出于明显的隐私原因,这是不可能的,除非通过 root。您试图利用的安全漏洞已经关闭了很长一段时间。

    【讨论】:

    • 没关系,我确信 Play Store 上的应用程序验证会通过魔法做到这一点
    • @MichelTremblaySt-Germain:“他们是 google play 上的很多应用程序”——请随意命名。
    • 我不能去哪里抹去这个话题和我的个人资料,我不需要在这里浪费时间和其他时间?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    相关资源
    最近更新 更多