我有一个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我添加了它。 –