生根並請求超級用戶權限在我的應用程序中啓用/禁用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. 如何在Android 4.4中以編程方式啓用/禁用GPS?
- 2. 如何在Android 6.x上以編程方式啓用或禁用GPS?
- 3. 如何以編程方式在android中啓用/禁用gps和移動數據?
- 4. 如何以編程方式在android手機中禁用GPS?
- 5. Android如何以編程方式啓用/禁用自動同步
- 6. 無法以編程方式在Android中禁用GPS
- 7. 以編程方式啓用/禁用gps android無法正常工作
- 8. 如何以編程方式啓用和禁用Android 4.2上的飛行模式?
- 9. 以編程方式啓用/禁用Log4jLogger?
- 10. 如何以編程方式啓用和禁用USB在Android應用程序
- 11. 我怎樣才能啓用禁用GPS在編程方式在Android?
- 12. 以編程方式開啓/關閉GPS
- 13. 在Windows 7上以編程方式啓用/禁用連接
- 14. Android以編程方式禁用onScroll()
- 15. 如何以編程方式在Android中啓用/禁用輔助功能服務
- 16. Android:以編程方式啓用/禁用相機
- 17. 如何在啓動時以編程方式禁用Spring @JmsListener
- 18. 如何以編程方式啓用/禁用移動數據
- 19. 如何以編程方式啓用/禁用IE代理設置?
- 20. 如何以編程方式啓用/禁用Windows功能
- 21. 如何以編程方式啓用/禁用Azure功能
- 22. 如何以編程方式啓用和禁用NETWORK_PROVIDER
- 23. 如何以編程方式禁用/啓用UIBarButtonItem
- 24. 如何以編程方式禁用SparkUI?
- 25. 如何以編程方式禁用cookie
- 26. Android:以編程方式禁用和啓用活動在android中不起作用
- 27. 如何以編程方式禁用/啓用Android中的物理鍵盤?
- 28. 如何在android中以編程方式禁用耳機檢測?
- 29. 如何在android中以編程方式禁用拼寫校正
- 30. Android M:如何以編程方式禁用打盹模式
哇太感謝你了,這是偉大的! – 2011-05-22 00:46:28