启动并请求超级用户权限后,我需要做什么才能在我的应用程序中启用/禁用gps?
发布于 2011-05-22 08:40:11
你不应该保护用户的隐私。然而,通过利用一个bug是可能的。查看以下内容以了解如何:
How can I enable or disable the GPS programmatically on Android?
请注意,这可能并不适用于所有版本的Android -请参阅
他们指出它已经修复,但我不确定哪个版本有修复(如果有的话)。
发布于 2016-03-16 18:09:27
在根设备上尝试此选项,只需使用su在高精度模式下启用gps
Process proc=Runtime.getRuntime().exec(new String[]{"su",
"pm grant com.your_app_packagename android.permission.WRITE_SECURE_SETTINGS",
"settings put secure location_providers_allowed gps,network,wifi"});
proc.waitFor();在后台线程上运行以下命令:)
此外,您还可以参考此链接here
发布于 2017-05-16 12:33:42
此代码适用于根目录下的 phones ,前提是将应用程序移动到 /system/aps,,并且他们在清单中具有以下权限
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>代码
private void turnGpsOn (Context context) {
beforeEnable = Settings.Secure.getString (context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
String newSet = String.format ("%s,%s",
beforeEnable,
LocationManager.GPS_PROVIDER);
try {
Settings.Secure.putString (context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
newSet);
} catch(Exception e) {}
}
private void turnGpsOff (Context context) {
if (null == beforeEnable) {
String str = Settings.Secure.getString (context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (null == str) {
str = "";
} else {
String[] list = str.split (",");
str = "";
int j = 0;
for (int i = 0; i < list.length; i++) {
if (!list[i].equals (LocationManager.GPS_PROVIDER)) {
if (j > 0) {
str += ",";
}
str += list[i];
j++;
}
}
beforeEnable = str;
}
}
try {
Settings.Secure.putString (context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
beforeEnable);
} catch(Exception e) {}
}https://stackoverflow.com/questions/6085254
复制相似问题