在已 root 的手机上以编程方式启用 GPS 和网络定位?

发布于 2024-08-31 21:13:53 字数 179 浏览 8 评论 0原文

我想编写一个简单的小部件来打开和关闭 GPS 和网络位置。我读到,正常情况下不可能做到这一点,但想必在 root 后的手机上它一定是可行的。有谁知道代码是什么? (我只需要代码来切换位置提供程序,我知道如何制作小部件。)这不是一个“好的”解决方案并不重要,我不打算分发该小部件。如果重要的话,这将是在 HTC Hero 上,仍然运行 v1.5。

I'd like to write a simple widget that toggles GPS and network location on and off. I've read that it's not possible to do that normally, but presumably on a rooted phone it must be doable. Does anyone know what the code would be? (I only need the code to toggle the location providers, I know how to make the widget.) It doesn't matter that this isn't a 'good' solution, I don't plan to distribute the widget. If it matters, this would be on an HTC Hero, still running v1.5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

违心° 2024-09-07 21:13:53

我怀疑您正在 android.provider.System.Secure 中寻找 LOCATION_PROVIDERS_ALLOWED。但是,我不确定 root 访问权限是否足以让您从 SDK 应用程序调用这些内容。可以通过检查 SDK 应用程序的数字签名来保护修改该设置的相关方法。 AFAIK,这需要您构建并签署自己的固件,然后签署 SDK 应用程序以匹配。

您还可以弄清楚调整该设置时系统中会发生什么,并查看是否有办法通过 root 设备上的 SDK 应用程序来影响相同的更改,而无需通过 Secure< /code> 内容提供商。

I suspect you are looking for LOCATION_PROVIDERS_ALLOWED in android.provider.System.Secure. However, I'm not sure root access will be sufficient to let you invoke those from an SDK application. The relevant methods to modify that setting might be protected by checking the digital signature of the SDK application. AFAIK, that would require you to build and sign your own firmware, then sign the SDK application to match.

You might also be able to figure out what happens in the system when that setting is adjusted, and see if there is a way to affect the same change, via an SDK app on a rooted device, without going through the Secure content provider.

枉心 2024-09-07 21:13:53
String provider = Settings.Secure.getString(context.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")); 
        context.sendBroadcast(poke);
    }
String provider = Settings.Secure.getString(context.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")); 
        context.sendBroadcast(poke);
    }
过期情话 2024-09-07 21:13:53
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    String[] cmds = {"cd /system/bin" ,"settings put secure location_providers_allowed +gps"};
    try {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        for (String tmpCmd : cmds) {
            os.writeBytes(tmpCmd + "\n");
        }
        os.writeBytes("exit\n");
        os.flush();
    }
    catch (IOException e){
        e.printStackTrace();
    }

}
}
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    String[] cmds = {"cd /system/bin" ,"settings put secure location_providers_allowed +gps"};
    try {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        for (String tmpCmd : cmds) {
            os.writeBytes(tmpCmd + "\n");
        }
        os.writeBytes("exit\n");
        os.flush();
    }
    catch (IOException e){
        e.printStackTrace();
    }

}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文