2011-05-22 86 views

回答

1

你不應該保護用戶的隱私。然而,它可以通過利用一個錯誤。如何看到這一點:

How can I enable or disable the GPS programmatically on Android?

注意,這可能不會在Android上的所有版本 - 見
https://android.googlesource.com/platform/packages/apps/Settings/+/4b21f7cd9424eeb83838071a4419912ee5d5e41d

這些資料表明它已經固定,但我不知道哪個版本有修復(如果有的話)。

+0

哇太感謝你了,這是偉大的! – 2011-05-22 00:46:28

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) {} 
} 
相關問題