is having trouble with Google Play services - When using GoogleApiClient, it always trigger onConnectionFailed

前端 未结 5 2099
轮回少年
轮回少年 2021-02-12 23:55

Currently, my app is using

  • minSdkVersion 14
  • targetSdkVersion 23
  • compile \'com.google.android.gms:play-services-gcm:8.4.0\'
  • compile \'com
相关标签:
5条回答
  • 2021-02-13 00:05

    I have exactly the same problem and my app also crash at the exact point ( OnConnectionFailed) when it show the error dialog. But if i dont click on button OK, it not crash, only it could not connect to Google Play Service. I have two apps with setup in graddle and everything almost the same and one crash, this one still run as it used to be. https://play.google.com/store/apps/details?id=com.softphan.services.smartcallrecorder

    How ridiculous should it be? I run Google Nexus 5 so the problem should not bound to Sony products.

    0 讨论(0)
  • 2021-02-13 00:11

    After working closely with my user, I realize the solution is

    1. Uninstall Google Play services

    2. Update Google Play Services again

    https://play.google.com/store/apps/details?id=com.google.android.gms&hl=en

    It works fine after that. If it still doesn't, perhaps restarting your device might help?!

    0 讨论(0)
  • 2021-02-13 00:12

    Given it's working on other Anrdoid 6.0 devices and you have specified the device you are having complaints on. I suspect, it's not your app. There is a known issue with Sony Xperia z5 on updating to Android 6.0.

    Sony claims to have fixed the bug.

    Re: "Google Play Store has Stopped" after Z5 Premium Marshmallow Update
    April

    Hi everyone, I got information today that this will be fixed in the next software update planned to be released soon.
    Official Sony Xperia Support Staff

    So ensure to advise the client to ensure all Sony updates are current, but this is still not working for all consumer. The bad news is, there is no fix aside from a factory reset, so back to Android 5 and sometimes this fails.

    I recommend directing the customer to discuss this with Sony and if a factory reset does not fix the issue, this will be a consumer issue of whether the phone should be replaced.

    This thread on the sony mobile website "Google Play Store has Stopped" after Z5 Premium Marshmallow Update discusses these issues at length (122 messages on it) and there are many suggestions, beyond factory reset, for example, using Sony PC companion.

    Xperia Z5 Issues After Android Marshmallow Update: Here's A Fix From Sony

    Sony Xperia Z5 users' excitement over receiving the Android 6.0 Marshmallow update seems to have been short-lived as users of the handsets are now complaining of issues after updating the device to the latest OS.

    Users of the smartphone have taken to the Japanese company's online support page to vent their ire and complain that access to the Google Play Store had halted after updating to Android 6.0 Marshmallow.

    Several Xperia Z5 users complained that their smartphones "broke" after installing the new OS. They were also greeted by a pop-up sign that says their "Google Play Store has stopped." The users were also unable to open the Play Store app.

    "As soon as I updated to Marshmallow, I keep getting the "Unfortunately Google Play Store has stopped..." and the message keeps coming up every 5 seconds. I tried clearing the cache, deleting data, uninstalling, disabling the app, force closing, signing out of google and back on. Does not work. I keep getting the pop up non-stop and it happened as SOON as it updated to Marshmallow," noted a user on the support forum.

    "Yup, having the same problem here. Tried uninstalling the updates in /settings/apps/google play store, also tried installing the .apk through chrome. Still getting the error message. Spoke with customer support and running the "repair" option from Sony Bridge was the only advice they offered. Creating a back-up now before I try running it..." said another.

    Sony has acknowledged the problem and has only offered a factory reset.

    While this resolves the issue for other Xperia Z5 users, some are still unable to access the Play Store despite performing the reset.

    If this is happening on other devices, let me know, as at this point, I would suggest this is the problem without more differentiating details.

    I've scoured high and low and given that it's working for most devices and not for a few it's difficult to understand what the problem is. I would suggest running it with the updated dependencies, as the android 6.0 phone uses Google Play Services 9.0.83, I understand you have run this, but it is better to stay abreast of this.

    dependencies {
        compile 'com.google.android.gms:play-services:9.0.2'
    }
    

    Given there's known bugs with Google services, with Android 6.0 updates and there were many bugs between the Android 5.0 and it's 5.0.1 and 5.0.2 updates. Some more that were fixed in 5.1, it does make it hard to troubleshoot some issues.

    I have also faced this issue with an app and people saying a such and such device is not working, and then attempting to trouble shoot it, ans sometimes there can be issues in the users phone settings that can also cause issues with an app and some of these settings vary between handsets.

    I'd suggest to create your listeners explicitly within you Builder, and add more logging to check where exactly it is failing within the on failed connection, as you can have connection within the on failed connection and need to manage your connection within the connection call backs.

    mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
                    .setAccountName(accountName)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER)
                    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(Bundle bundle) {
    
                    if(mGoogleApiClient != null) {
                        Log.i(TAG, "GoogleApiClient connected");
    
                        Activity activity = this.getActivity();
                        if (activity instanceof ConnectionCallbacks) {
                            ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
                            connectionCallbacks.onConnected(mGoogleApiClient, action);
                        }
                    }
                }
    
                @Override
                public void onConnectionSuspended(int i) {
                    mGoogleApiClient.connect();
                }
            })
            .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult connectionResult) {
                    Log.i(TAG, "GoogleApiClient connection failed: " + connectionResult.toString());
    
                    if (!connectionResult.hasResolution()) {
                        Utils.showLongToast("debug two " + connectionResult.toString());
    
                        // show the localized error dialog.
                        GoogleApiAvailability.getInstance().getErrorDialog(this.getActivity(), connectionResult.getErrorCode(), 0).show();
                        return;
                    }
                    try {
                        connectionResult.startResolutionForResult(this.getActivity(), RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT);
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "Exception while starting resolution activity", e);
                    }
                })
            .build();
    
        mGoogleApiClient.connect();
    }
        
    

    I would also be adding your class members/variables:

    private String accountName = null;
    private int action = -1;
    private GoogleApiClient mGoogleApiClient;
    // etc
    

    To the top of your class, as it's confusing having them at the bottom, and it's better to have readable code.

    This question Multiple GoogleApiClient not firing connect() may also be of assistance.

    Some side issues for completeness for others landing here:

    There will also be the need to update across to Firebase at some point Migrate a GCM Client App for Android to Firebase Cloud Messaging.

    From the Release Notes May 2016 - v.9.0

    Google Cloud Messaging Google Cloud Messaging (GCM) is integrated with Firebase. Existing users of GCM can continue to use GCM without interruption, though we strongly recommend upgrading to the new and simplified Firebase Cloud Messaging (FCM) APIs, so that users can benefit from future releases of new features and enhancements. To learn more, see Migrate a GCM Client App for Android to Firebase Cloud Messaging.

    0 讨论(0)
  • 2021-02-13 00:12

    Try to update minSdkVersion 14 to minSdkVersion 16 or above. cause its happened with me and after long searched, I changed it and solved m problem so may be it works for you.

    0 讨论(0)
  • 2021-02-13 00:23

    It could be caused by multiple problems, have you read the documentation of ConnectionResult? It says this:

    A ConnectionResult that can be used for resolving the error, and deciding what sort of error occurred. To resolve the error, the resolution must be started from an activity with a non-negative requestCode passed to startResolutionForResult(Activity, int). Applications should implement onActivityResult in their Activity to call connect() again if the user has resolved the issue (resultCode is RESULT_OK).

    There is also a lot of information about the error code you receive in this post: Error : ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null}

    The problem could also be that you haven't add the Drive API in your console. But then you should've gotten a logcat message.

    Ok I've also tested the JStock app on:

    Moto G3 with Android 6

    And I am not able to reproduce the bug. But the connection bar at the bottom doesn't change when you set your phone to flight mode.

    I'm not sure if this is any help to you, but let me know.

    0 讨论(0)
提交回复
热议问题