我有一個Android應用程序發送GPS位置到DB。 我今天測試過,發現位置管理器需要調用requestLocationUpdates
的權限。requestLocationUpdates權限
我想設置允許的權限,我不想問設備或用戶的權限。
現在,代碼需要添加一些代碼,要求准予?
/**
* Enable location services
*/
public void connect() {
Log.d(TAG, ".connect() entered");
// Check if location provider is enabled
String locationProvider = LocationManager.NETWORK_PROVIDER;
if (!locationManager.isProviderEnabled(locationProvider)) {
Log.d(TAG, "Location provider not enabled.");
app.setCurrentLocation(null);
return;
}
// register for location updates, if location provider and permission are available
String bestProvider = locationManager.getBestProvider(criteria, false);
if (bestProvider != null) {
locationManager.requestLocationUpdates(bestProvider, Constants.LOCATION_MIN_TIME, Constants.LOCATION_MIN_DISTANCE, this);
app.setCurrentLocation(locationManager.getLastKnownLocation(locationProvider));
}
}
/**
* Disable location services
*/
public void disconnect() {
Log.d(TAG, ".disconnect() entered");
String locationProvider = LocationManager.NETWORK_PROVIDER;
if (locationManager.isProviderEnabled(locationProvider)) {
locationManager.removeUpdates(this);
}
}
我已經加入體現了。 PS:此權限是新近需要的,因爲我幾天前在相同設備(Android 4.4)上測試了應用程序,並且它運行良好。 自2017/08/21以來Android上的某些默認權限可能已更改嗎?如果是的話,我該如何改變它?
*我想設置權限允許的我不想問設備或用戶的許可。*太糟糕了,你想要的是不可能 –
你可以發佈一些代碼嗎? –
@Sandeepdhiman我添加了它。 –