Why doesn't LocationSettingsResult startResolutionForResult call onActivityResult?

I saw this dialog Q & A LocationSettingsRequest - onActivityResult () is skipped . This is not the same problem because everything is already running in the Activity.

The code used is almost verbatim, as indicated in the Google Play Services examples.

I have a LocationActivity activity that connects to a GoogleApiClient to get the user's location. After connecting, I create a LocationSettingsRequest to make sure location settings are enabled. This operation implements ResultCallback<LocationSettingsResult> .

ResultCallback<LocationSettingsResult>.onResult() is called, and if result.getStatus().getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED is called status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS) displayed status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS) and displayed. The problem, no matter what is selected, onActivityResult() never called.

 @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; } } 

I am never here:

 @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; } } 

Aside. It worked several times on my S3. From what I can say, it stopped working when I decided never to ask again. But it never worked on an emulator or Tab 10, and it no longer works on my S3.

+5
source share
3 answers

Well, I feel stupid. My activity had noHistory="true" in the manifest, so when another activity was launched, there was nothing to return.

+7
source

You can check the Google Play location example , as your code is very similar to it.

From what I can tell from your samples, onResult () cannot be called, because the case is not LocationSettingsStatusCodes.RESOLUTION_REQUIRED . It does not call startResolutionForResult or the underlying setActivityForResult inside it.

0
source

In my case, the following error occurred: I used

 public abstract class AGoogleDriveBase extends ABase implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { //... @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { //... 

and this function is not called with

 try { result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION); } catch (SendIntentException e) { Log.e(TAG, "Exception while starting resolution activity", e); } 

because when I used the main action

 public class myAct extends AGoogleDriveBase implements ... { //... @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

super method is not called (this line does not exist):

  super.onActivityResult(requestCode, resultCode, data); 
0
source

Source: https://habr.com/ru/post/1238663/


All Articles