【问题标题】:App is having trouble with Google Play Services. If it persists, please contact the developer for assistance应用程序在使用 Google Play 服务时遇到问题。如果仍然存在,请联系开发人员寻求帮助
【发布时间】:2017-02-13 10:12:43
【问题描述】:

我正在尝试将适用于 Android 的 Google Drive API 与我的 Android 应用程序集成。

我的前辈使用应用包名称和我机器上的SHA1 在Google Developer 控制台上创建了一个项目,并生成了OAuth 2.0 客户端ID(我无权访问该帐户)。

点击按钮后,我必须允许用户访问 Drive 上的文件,以便将它们上传到服务器。

我调用以下代码onClick()

mGoogleApiClient = new GoogleApiClient.Builder(Activity.this)
    .addApi(Drive.API)
    .addScope(Drive.SCOPE_FILE)
    .addConnectionCallbacks(Activity.this)
    .addOnConnectionFailedListener(Activity.this)
    .build();

mGoogleApiClient.connect();

这会调用onConnectionFailed() 回调:

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Log.i(TAG, "Connection failed");
    if (connectionResult.hasResolution()) {
        try {
            Log.i(TAG, "Connection failed - Trying again");
            connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        Log.i(TAG, "Connection failed, Code : " + connectionResult.getErrorCode());
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}

连接失败并再次尝试。重试时,它会调用onActivityResult() 并再次尝试连接:

public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    if (requestCode == Constants.RESOLVE_CONNECTION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        Log.i(TAG, "Code match");
        mGoogleApiClient.connect();
    }
}

这一次连接尝试再次失败,错误代码为 8,并显示消息“应用程序在使用 Google Play 服务时遇到问题。如果问题仍然存在,请联系开发人员寻求帮助。”

我也读过这个: <Your App> is having trouble with Google Play services - When using GoogleApiClient, it always trigger onConnectionFailed,但没有帮助。

我尝试在 Google 上查找它,但没有任何帮助。任何帮助都会很棒!

【问题讨论】:

    标签: android google-play-services


    【解决方案1】:

    尽量不要在你的点击onClick()函数中实例化mGoogleApiClient。如果您检查此android-demo 和此drive quickstart,mGoogleApiClient 将在onResume() 生命周期中实例化:

    @Override
    protected void onResume() {
    super.onResume();
    if (mGoogleApiClient == null) {
    // Create the API client and bind it to an instance variable.
    // We use this instance as the callback for connection and connection
    // failures.
    // Since no account name is passed, the user is prompted to choose.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Drive.API)
    .addScope(Drive.SCOPE_FILE)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();
    }
    // Connect the client. Once connected, the camera is launched.
    mGoogleApiClient.connect();
    }
    

    查看官方Android Drive API了解更多信息。

    【讨论】:

    • 是的。我已经检查过了。但这会导致帐户选择对话框弹出onResume()。我不要那个。我希望仅在用户想要从 Google Drive 访问文件时才显示该对话框。
    猜你喜欢
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多