2011-05-22 83 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) {} 
} 
相关问题