我正在开发适用于Android的App,它允许您在开发人员设置中未启用它来模拟您的位置。
我尝试了一些事情,但没有取得任何成功。
如果启用了设置,我的实际代码会起作用,但如果禁用它则不会(即使应用程序是系统应用程序)
我的代码:
if (mLocationManager.getProvider(GPS_PROVIDER_NAME) != null) {
mLocationManager.removeTestProvider(GPS_PROVIDER_NAME);
}
mLocationManager.addTestProvider(
GPS_PROVIDER_NAME,
"requiresNetwork" == "",
"requiresSatellite" == "",
"requiresCell" == "",
"hasMonetaryCost" == "",
"supportsAltitude" == "",
"supportsSpeed" == "",
"supportsBearing" == "",
android.location.Criteria.POWER_LOW,
android.location.Criteria.ACCURACY_FINE
);
currentLocation = new Location(GPS_PROVIDER_NAME);
currentLocation.setLatitude(mockLocationLatLng[0]);
currentLocation.setLongitude(mockLocationLatLng[1]);
currentLocation.setTime(System.currentTimeMillis());
currentLocation.setAltitude(1);
currentLocation.setSpeed(200);
currentLocation.setAccuracy(500);
mLocationManager.setTestProviderLocation(GPS_PROVIDER_NAME, currentLocation);
mLocationManager.setTestProviderEnabled(GPS_PROVIDER_NAME, true);
mLocationManager.setTestProviderStatus(GPS_PROVIDER_NAME, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
我做错了什么吗? 遗憾的是,当你拥有系统/应用程序权限时,我不知道该怎么做。
您有什么建议如何解决这个问题? 我不需要一个完全正常工作的程序代码,只是一种如何完成它的方法。
感谢您的帮助!