2016-10-05 23 views
1

我正在尝试将Android的Google Drive API与我的Android应用程序集成。应用程序在Google Play服务中遇到问题。如果问题仍然存在,请联系开发人员寻求帮助

我的大人在Google Developer Console上使用应用程序包名称和我的机器上的SHA1创建了一个项目,并生成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,给出了消息“应用程序是有问题的播放服务。如果问题仍然存在,请联系开发人员寻求帮助。“

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

我试着在谷歌上查找它,但没有任何帮助。任何援助将是伟大的!

回答

0

尽量不要在您的点击onClick()函数中安装mGoogleApiClient函数。如果您选中此android-demodrive quickstart的mGoogleApiClient被实例化在onResume() lifecycyle:

@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以获得更多信息。

+0

是的。我已经检查过。但是这会导致账户选择对话框弹出'onResume()'。我不要那个。我希望仅在用户想要访问Google云端硬盘中的文件时才显示该对话框。 – Bot

相关问题