这个问题可能与手机上Google帐户的验证有关。可以尝试以下两种方式解决:
LocationRequest locationRequest = new LocationRequest();
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setSmallestDisplacement(10);
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, locationRequest);
这里可以设置参数为false。
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext()).addApi(Auth.GOOGLE_SIGN_IN_API).addApi(LocationServices.API).build();
mGoogleApiClient.connect();
val builder = LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest)
val task: Task = LocationServices.getSettingsClient(context).checkLocationSettings(builder.build())
task.addOnSuccessListener {
// do nothing
}
task.addOnFailureListener { exception ->
if (exception is ResolvableApiException) {
try {
// ask permission from user
exception.startResolutionForResult(this, REQUEST_LOCATION)
} catch (sendEx: IntentSender.SendIntentException) {
// Ignore the error.
}
}
}