<Your App>在使用Google Play服务时出现问题 - 使用GoogleApiClient时,它始终会触发onConnectionFailed

Che*_*eng 16 android google-play-services google-signin

目前,我的应用正在使用

  • minSdkVersion 14
  • targetSdkVersion 23
  • 编译'com.google.android.gms:play-services-gcm:8.4.0'
  • 编译'com.google.android.gms:play-services-base:8.4.0'
  • 编译'com.google.android.gms:play-services-analytics:8.4.0'
  • 编译'com.google.android.gms:play-services-ads:8.4.0'
  • 编译'com.google.android.gms:play-services-drive:8.4.0'

我使用以下代码来执行GoogleApiClient连接.

public class GoogleApiClientFragment extends Fragment implements
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    public interface ConnectionCallbacks {
        void onConnected(GoogleApiClient googleApiClient, int action);
        void onCancel(int action);
    }

    public static GoogleApiClientFragment newInstance(String accountName, int action) {
        GoogleApiClientFragment googleApiClientFragment = new GoogleApiClientFragment();
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_EXTRA_ACCOUNT_NAME, accountName);
        bundle.putInt(INTENT_EXTRA_ACTION, action);
        googleApiClientFragment.setArguments(bundle);
        return googleApiClientFragment;
    }

    /**
     * Handles resolution callbacks.
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT) {
            if (resultCode == Activity.RESULT_OK) {
                mGoogleApiClient.connect();
            } else {
                Activity activity = this.getActivity();
                if (activity instanceof ConnectionCallbacks) {
                    ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
                    connectionCallbacks.onCancel(action);
                }
            }
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);

        Bundle bundle = this.getArguments();
        this.accountName = bundle.getString(INTENT_EXTRA_ACCOUNT_NAME);
        this.action = bundle.getInt(INTENT_EXTRA_ACTION);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
                    .setAccountName(accountName)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();

            mGoogleApiClient.connect();
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
        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) {
        Log.i(TAG, "GoogleApiClient connection suspended");
    }

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

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

    public static final int ACTION_LOAD_FROM_CLOUD = 0;
    public static final int ACTION_SAVE_TO_CLOUD = 1;
    private static final String INTENT_EXTRA_ACCOUNT_NAME = "INTENT_EXTRA_ACCOUNT_NAME";
    private static final String INTENT_EXTRA_ACTION = "INTENT_EXTRA_ACTION";

    private static final String TAG = "GoogleApiClientFragment";
}
Run Code Online (Sandbox Code Playgroud)

某些用户(并非所有用户)都遇到以下问题.

使用Google Play服务时遇到问题.如果问题仍然存在,请与开发人员联系以获取帮助.

在此输入图像描述

错误对话框是由于GoogleApiAvailability.getInstance().getErrorDialog代码所致onConnectionFailed.

每当

        mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
                .setAccountName(accountName)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addScope(Drive.SCOPE_APPFOLDER)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
Run Code Online (Sandbox Code Playgroud)

被执行,它总是被击中

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Run Code Online (Sandbox Code Playgroud)

当我打印出connectionResult使用时toString,它给出了

ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null, message=null}
Run Code Online (Sandbox Code Playgroud)

我的一个用户有以下规范.

  • 索尼Xperia z5
  • Android 6
  • Google Play服务9.0.83
  • 他的设备中只有1个Google帐户

我甚至尝试使用Google Play Services 9.0.1重新编译APK.但是,同样的问题仍然存在.

关于如何解决问题的任何想法?

Yve*_*omb 11

鉴于它正在处理其他Anrdoid 6.0设备,并且您已经指定了您正在投诉的设备.我怀疑,这不是你的应用程序.Sony Xperia z5在更新到Android 6.0时存在已知问题.

索尼声称修复了这个漏洞.

回复:"谷歌Play商店已经停止"Z5 Premium Marshmallow Update
4月之后

大家好,我今天得到的信息是,这将在计划即将发布的下一个软件更新中修复.
Sony Xperia官方支持人员

因此,请确保建议客户确保所有索尼更新都是最新的,但这仍然不适用于所有消费者.坏消息是,除了工厂重置之外没有其他解决方案,所以回到Android 5,有时这会失败.

我建议指导客户与索尼讨论这个问题,如果出厂重置不能解决问题,这将是消费者是否应该更换手机的问题.

在Z5 Premium Marshmallow Update之后,索尼移动网站"谷歌Play商店停止了"中的这个帖子详细讨论了这些问题(上面有122条消息),除了出厂重置之外,还有很多建议,比如使用索尼PC伴侣.

Android Marshmallow更新后的Xperia Z5问题:这是索尼的修复

索尼Xperia Z5用户对接收Android 6.0 Marshmallow更新的兴奋似乎是短暂的,因为手机的用户现在在将设备更新到最新操作系统后抱怨问题.

智能手机的用户已经访问了日本公司的在线支持页面以发泄他们的愤怒,并抱怨在更新到Android 6.0 Marshmallow之后,对Google Play商店的访问已经停止.

一些Xperia Z5用户抱怨他们的智能手机在安装新操作系统后"破了".他们还受到一个弹出式标志的欢迎,他们说他们的"Google Play商店已经停止了".用户也无法打开Play商店应用.

"当我更新到Marshmallow时,我不断得到"不幸的是Google Play商店已经停止......"并且消息每5秒钟就会出现一次.我尝试清除缓存,删除数据,卸载,禁用应用程序,强制关闭,退出谷歌并重新开启.不起作用.我一直不停地弹出弹出窗口,因为它更新到Marshmallow,"支持论坛上的一位用户指出.

"是的,在这里遇到同样的问题.尝试卸载/ settings/apps/google play商店中的更新,也尝试通过chrome安装.apk.仍然收到错误消息.发表客户支持并运行"修复"选项索尼大桥是他们提供的唯一建议.在我尝试运行它之前创建一个备份......"另一个说.

索尼已经承认了这个问题并且只提供了出厂重置.

虽然这解决了其他Xperia Z5用户的问题,但有些用户仍然无法访问Play商店,尽管执行了重置.

如果在其他设备上发生这种情况,请告诉我,在这一点上,我会建议这是问题而没有更多区分细节.

我已经高高低调了,因为它适用于大多数设备而不是少数设备,因此很难理解问题所在.我建议运行它与更新的依赖项,因为Android 6.0手机使用Google Play Services 9.0.83,我知道你已经运行了这个,但最好还是及时了解这一点.

dependencies {
    compile 'com.google.android.gms:play-services:9.0.2'
}
Run Code Online (Sandbox Code Playgroud)

鉴于谷歌服务存在已知错误,Android 6.0更新,Android 5.0及其5.0.1和5.0.2更新之间存在许多错误.在5.1中修复了一些,它确实很难解决一些问题.

我也遇到过这个问题的应用程序和人们说这样的设备无法正常工作,然后尝试解决问题,有时可能会出现问题,用户手机设置也会导致应用程序出现问题这些设置在手机之间有所不同.

我建议在您的Builder中显式创建侦听器,并添加更多日志记录以检查在失败连接中确切失败的位置,因为您可以在失败的连接中建立连接并需要在连接调用中管理连接背上.

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();
}
Run Code Online (Sandbox Code Playgroud)

我还要添加你的类成员/变量:

private String accountName = null;
private int action = -1;
private GoogleApiClient mGoogleApiClient;
// etc
Run Code Online (Sandbox Code Playgroud)

在你的班级的顶部,因为它让他们在底部令人困惑,并且最好有可读的代码.

此问题多个GoogleApiClient未触发connect()也可能有所帮助.

在这里登陆的其他人的完整性有些问题:

还需要在某些时候更新到Firebase,将适用于Android的GCM客户端应用程序迁移到Firebase云消息传递.

摘自2016年5月发行说明 - v.9.0

Google云消息传递Google云消息传递(GCM)与Firebase集成在一起.GCM的现有用户可以继续使用GCM而不会中断,但我们强烈建议您升级到新的和简化的Firebase云消息传递(FCM)API,以便用户可以从未来版本的新功能和增强功能中受益.有关详情,请参阅将适用于Android的GCM客户端应用迁移到Firebase云消息传递.


Che*_*eng 4

在与我的用户密切合作后,我意识到解决方案是

1.卸载Google Play服务

在此输入图像描述

在此输入图像描述

2.再次更新Google Play服务

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

在此输入图像描述

之后就可以正常工作了。如果仍然没有,也许重新启动您的设备可能会有所帮助?!


归档时间:

查看次数:

20201 次

最近记录:

9 年,1 月 前