How do you suggest a user to update Google Play services?

I can easily find that the google play device app for the device needs to be updated and submit getErrorDialogFragment () to prompt the user to update it:

     GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance();
     mServiceAvailabilityCode = googleApi.isGooglePlayServicesAvailable(this);
     if (mServiceAvailabilityCode == ConnectionResult.SUCCESS) {
          ...
     else {
        if (googleApi.isUserResolvableError(mServiceAvailabilityCode)) {
            switch (mServiceAvailabilityCode) {
                    ....
            case SERVICE_VERSION_UPDATE_REQUIRED:
                googleApi.showErrorDialogFragment(SplashActivity.this, mServiceAvailabilityCode, PLAY_SERVICES_RESOLUTION_REQUEST);
                break;
                    ....
                }

However, if Google’s services are disabled and out of date , then the user is presented with a dialog box with the Refresh button, as soon as the user clicks on it, the application immediately returns to onActivityResult, which then captures the response and request code in OnActivityResult as follows:

       @Override
       protected void onActivityResult(int requestCode, int mServiceAvailabilityCode, Intent data) {
          super.onActivityResult(requestCode, mServiceAvailabilityCode, data);
          switch (requestCode) {
          case PLAY_SERVICES_RESOLUTION_REQUEST:
                finish();
                // do i need to launch app manager-> app info for google play services ?

, "" Android Playstore "Playstor services" , . "" onActivityResult. . Android ? OnActivityResult?

+4
4

, 2 Google Play (GPS). GPS , Google Play Store (GPT) .

Google Play , showErrorDialogFragment ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ( 2), .

GPS , , googleApiAvailability api. isGooglePlayServicesAvailable(), , , . , , . isGooglePlayServicesAvailable() .

. , showErrorDialogFragment, SERVICE_VERSION_UPDATE_REQUIRED.

Android , pendingIntent Google Play Store (GPT) GPS, , GPT GPS ENABLED. showErrorDialogFragment, onActivityResult , GPT.

- codig onActivityResult. isGooglePlayServicesAvailable(). (SERVICE_VERSION_UPDATE_REQUIRED), showErrorDialogFragment onActivityResult, ConnectionResult.SERVICE_DISABLED ( 3). , google play. , , isGooglePlayServicesAvailable, , google - . , onActivityResult , isGooglePlayServicesAvailable , . , , Google Play, .

(, , googleApiAvailability - (.. ConnectionResult.SERVICE_DISABLED aka 3), , GPS.)

+6

GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
int result = googleAPI.isGooglePlayServicesAvailable(this);

if(result != ConnectionResult.SUCCESS) {
    if(googleAPI.isUserResolvableError(result)) {
       //prompt the dialog to update google play
  googleAPI.getErrorDialog(this,result,PLAY_SERVICES_RESOLUTION_REQUEST).show();

    }
}
else{
  //google play up to date
}
+3

Google Play Services Play Store . Play Store.

- .

, ACTION_VIEW,

String LINK_TO_GOOGLE_PLAY_SERVICES = "play.google.com/store/apps/details?id=com.google.android.gms&hl=en";
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + LINK_TO_GOOGLE_PLAY_SERVICES)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://" + LINK_TO_GOOGLE_PLAY_SERVICES)));
}
0

Not sure which version of Google the bug is fixed in, but with the latest 11.6.0 you can get the correct statusCode and dialog that will lead to settings to enable Google Play services.

Logcat:

11-24 05:48:07.266 V/FA: Activity resumed, time: 2070779368
11-24 05:48:07.320 W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_DISABLED, resolution=null, message=null}

Dialogue: enter image description here

0
source

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


All Articles