我已经反编译了
com.lexa.fakegps您提到的问题以及它的操作:
private int setMockLocationSettings() { int value = 1; try { value = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION); Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 1); } catch (Exception e) { e.printStackTrace(); } return value;}private void restoreMockLocationSettings(int restore_value) { try { Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, restore_value); } catch (Exception e) { e.printStackTrace(); }}int value = setMockLocationSettings();//toggle ALLOW_MOCK_LOCATION ontry { mLocationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, fake_location);} catch (SecurityException e) { e.printStackTrace();} finally { restoreMockLocationSettings(value);//toggle ALLOW_MOCK_LOCATION off}由于这些代码的执行时间非常短,因此其他应用几乎无法检测到ALLOW_MOCK_LOCATION的更改。
另外,您还需要:
1.要求对设备具有root权限
2.将应用程序移至
/system/app或
/system/priv-app
我在我的项目中尝试过,并且效果很好。



