生根並請求超級用戶權限在我的應用程序中啓用/禁用gps需要做什麼?如何在rooted android上以編程方式禁用/啓用gps?
2
A
回答
1
你不應該保護用戶的隱私。然而,它可以通過利用一個錯誤。如何看到這一點:
How can I enable or disable the GPS programmatically on Android?
注意,這可能不會在Android上的所有版本 - 見
https://android.googlesource.com/platform/packages/apps/Settings/+/4b21f7cd9424eeb83838071a4419912ee5d5e41d
這些資料表明它已經固定,但我不知道哪個版本有修復(如果有的話)。
1
Root權限的設備嘗試這只是使用su的高精確度模式
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();
啓用GPS上運行後臺線程:)
進一步您可以參考此鏈接here
0
這些命令此代碼適用於ROOTED手機如果該應用移至/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) {}
}
相關問題
- 1. 如何以編程方式在Ionic Framework或Cordova中啓用和禁用GPS
- 2. 以編程方式啓用/禁用Log4jLogger?
- 3. 如何以編程方式啓用和禁用USB在Android應用程序
- 4. 我怎樣才能啓用禁用GPS在編程方式在Android?
- 5. 以編程方式開啓/關閉GPS
- 6. 在Windows 7上以編程方式啓用/禁用連接
- 7. 如何以編程方式在Android中啓用/禁用輔助功能服務
- 8. 如何以編程方式啓用/禁用Windows功能
- 9. 如何以編程方式啓用/禁用Azure功能
- 10. 如何以編程方式啓用/禁用IE代理設置?
- 11. 如何以編程方式啓用/禁用移動數據
- 12. 如何以編程方式禁用/啓用Android中的物理鍵盤?
- 13. 如何在android中以編程方式禁用拼寫校正
- 14. 如何在android中以編程方式自動開啓和關閉gps
- 15. 以編程方式檢查iPhone是否已啓用GPS
- 16. 如何在Android中以編程方式啓用HSDPA?
- 17. 如何在Android中以編程方式啓用動畫
- 18. 以編程方式啓用/禁用沉浸模式
- 19. 谷歌地圖是以編程方式啓用GPS?
- 20. 以編程方式啓用GPS(無導航到位置設置)
- 21. 如何在android上以編程方式備份應用程序
- 22. 我可以通過我的應用程序以編程方式啓用GPS嗎?
- 23. 如何以編程方式禁用佈局和其內容android
- 24. 如何以編程方式禁用android硬件按鈕?
- 25. 以編程方式啓用和禁用自動旋轉?
- 26. 如何以編程方式禁用Android上的onClick處理程序AppWidget按鈕
- 27. 如何啓用Android的GPS編碼
- 28. 以編程方式啓用/禁用鍵盤聲音和振動
- 29. Android的啓用和禁用GPS
- 30. 如何在運行時以編程方式啓用/禁用Firebug Lite?
哇太感謝你了,這是偉大的! – 2011-05-22 00:46:28