我正在使用google位置api获取位置。我正面临的问题是,当用户关闭GPS时,我没有收到Lcoation,根据this帖子,我们可以访问基于网络的位置 - 尽管GPS已关闭。但是当用户关闭位置访问权限时,我并未获得位置信息。当位置访问关闭时,无法访问基于网络的位置
这是我的服务来获取位置
public class LocationUpdateService extends Service implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener, ResultCallback<Status> {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startLocationUpdates();
return START_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
LogUtils.LOGI(TAG, "Service created");
buildGoogleApiClient();
setupBroadCastListenerForGpsStatusChange();
initLastLocationDetails();
}
/**
* Requests location updates from the FusedLocationApi.
*/
protected void startLocationUpdates() {
if (!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
} else {
mRequestingLocationUpdates = true;
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
}
/**
* Builds a GoogleApiClient. Uses the {@code #addApi} method to request the
* LocationServices API.
*/
protected synchronized void buildGoogleApiClient() {
LogUtils.LOGI(TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(ActivityRecognition.API)
.build();
createLocationRequest();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setSmallestDisplacement(SMALLEST_DISTANCE_METERS);
}
@Override
public void onConnected(Bundle connectionHint) {
startLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
//location operations
}
}
所以我的问题是,难道真的有可能当位置的访问被禁止访问的位置(不会持续缓存的位置),如果是,是什么错我的代码
请在回答之前仔细阅读此问题,请参阅我正在使用谷歌播放位置api,并发布Android本地位置api的答案 – droidev