LocationServices.SettingsApi Reset SETTINGS_CHANGE_UNAVAILABLE flag

后端 未结 1 872
花落未央
花落未央 2021-02-05 14:51

Updating to Google Play Services v7.0+, and based in this sample for LocationUpdates in Android, I have the following code to connect to the LocationServices.SettingsApi

相关标签:
1条回答
  • 2021-02-05 15:13

    LocationSettingsRequest.Builder has a method setAlwaysShow that changes the buttons of the dialog:

    Always show the dialog, without the "Never" option to suppress future dialogs from this app. When this flag is set to true, the dialog will show up if the location settings do not satisfy the request, even if a user has previously chosen "Never". NOTE: Only use this method if your dialog is the result of an explicit user-initiated action that requires location to proceed. Canceling this dialog should also cancel the initiated action.

    Instead the default Yes, Not now and Never buttons if you call setAlwaysShow(true); you will have only Yes and No, so the user won't choose Never and you will never receive SETTINGS_CHANGE_UNAVAILABLE

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    builder.setAlwaysShow(true); 
    mLocationSettingsRequest = builder.build();
    
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(
                    mLocationClient,
                    mLocationSettingsRequest
            );
    
    result.setResultCallback(this);
    
    0 讨论(0)
提交回复
热议问题