Ich habe dieses Q & A LocationSettingsRequest dialog - onActivityResult() skipped gesehen. Es ist nicht das gleiche Problem, da bereits alles in einer Aktivität ausgeführt wird.Warum ruft LocationSettingsResult startResolutionForResult onActivityResult nicht auf?
Der verwendete Code ist fast wörtlich, was in den Google Play Services Beispielen angegeben ist.
Ich habe eine Aktivität, LocationActivity
, die eine Verbindung zum GoogleApiClient herstellt, um den Standort des Benutzers abzurufen. Sobald ich verbunden bin, erstelle ich eine LocationSettingsRequest
, um sicherzustellen, dass die Standorteinstellungen aktiviert sind. Die Aktivität implementiert ResultCallback<LocationSettingsResult>
.
wird ResultCallback<LocationSettingsResult>.onResult()
aufgerufen und wenn result.getStatus().getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED
dann status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS)
aufgerufen wird und der Dialog angezeigt wird. Das Problem, egal was ausgewählt ist, onActivityResult()
wird nie aufgerufen.
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "GoogleApiClient connected");
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(new LocationRequest().setPriority(LocationRequest.PRIORITY_LOW_POWER));
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(this);
}
.
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
Log.d(TAG, "onResult() called with: " + "result = [" + status.getStatusMessage() + "]");
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
getLocation();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.d(TAG, "", e);
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
showManualInputDialog();
break;
}
}
ich nie hier:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult() called with: " + "requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]");
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
retryConnecting();
break;
case REQUEST_CHECK_SETTINGS:
if (resultCode == Activity.RESULT_OK) {
getLocation();
} else {
showManualInputDialog();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
Als Nebenwirkung. Es funktionierte ein paar Mal auf meiner S3. Von dem, was ich sagen kann, hörte es auf zu arbeiten, wenn ich mich entschied, nie wieder zu fragen. Aber es hat noch nie auf einem Emulator oder einem Tab 10 funktioniert und es funktioniert nicht mehr auf meinem S3.
Haben Sie OnActivity in derselben Aktivität deklariert? –