如何启用GPS的安卓编码 [英] How to enable GPS in android coding

查看:126
本文介绍了如何启用GPS的安卓编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  启用GPS编程喜欢塔斯克

好吧,我知道有问过同样的问题,但所有的答案是NO。事实证明,启用GPS可以在编码来完成。不信?尝试所谓的瞭望的应用程序。我相信这是为了实现这方面的一些解决办法。

Ok, I know there is same question asked before but all answer is "NO". It is proven that enable GPS can be done in coding. Don't believe? try out an application called "LOOKOUT". I believe there is some workaround in order to achieve this.

我通过了望AndroidManifest.xml中,我发现了什么,他们只用读了

I had read through lookout AndroidManifest.xml, what i found out they only use

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

任何人都知道他们是如何成功地做到这一点?背后是什么秘密?我个人成功地做到这一点只有在应用程序安装为系统应用程序,也需要两个权限

Anyone have idea how they managed to do this? what is the secret behind? I personally managed to do this only if the application is install as system app and also require two permission

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>

我的code:

My Code:

Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, true);

感谢你。

推荐答案

根据这帖子在寻找支持论坛,他们无法以编程方式启用GPS。

According to this post on the Lookout support forums, they are unable to programmatically enable GPS.

如果观景台可以远程启用GPS接收器,然后使用该服务,然后将其关闭 - 我们会的,但遗憾的是没有禁用GPS的一切比了望等,如果你禁用了GPS接收器,没有应用可以利用它。 启用GPS接收器需要用户手工完成。

If Lookout could enable the GPS receiver remotely, then use the service, then turn it off – we would, but unfortunately there is no "disable GPS for everything other than Lookout" and if you have disabled the GPS receiver, no application can make use of it. Enabling the GPS receiver requires a user to do it manually.

编辑:它看起来像了望他们是最有可能的,现在利用安全漏洞来完成这个新版本。它不能保证继续工作,但根据从4月份开放的Andr​​oid bug报告 2010 ,code类似于以下将成功编程方式启用/禁用GPS(至少要等到这个安全漏洞是固定的):

It looks like in the new version of Lookout they are most likely now exploiting a security flaw to accomplish this. It is not guaranteed to continue to work, but according to an open Android bug report from April 2010, code similar to the following will successfully programmatically enable/disable GPS (at least until the flaw is fixed):

private void toggleGPS(boolean enable) {
    String provider = Settings.Secure.getString(getContentResolver(), 
        Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(provider.contains("gps") == enable) {
        return; // the GPS is already in the requested state
    }

    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"));
    context.sendBroadcast(poke);
}

另外,看问题启用GPS编程就像塔斯克和< A HREF =htt​​p://forum.xda-developers.com/showthread.php?t=697465> XDA线程提到有了解讨论人如何使用这种方法。

Also, see the question "Enable GPS programmatically like Tasker" and the XDA thread mentioned there for more discussion on how people have used this method.

如果你使用这种方法,你应该清楚你的应用程序的潜在用户,因为这是一个巨大潜在的隐私问题。

If you do use this method, you should make it clear to potential users of your application, since this is a HUGE potential privacy concern.

这篇关于如何启用GPS的安卓编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆