【发布时间】:2014-05-19 11:04:55
【问题描述】:
我正在开发一个想要使用 Google API 的 Android 应用程序。为此,我导入了 google-play-service-lib 项目。
我正在关注这个link 来初始化 GoogleApiClient 对象。
我的代码:
1) 在onCreate() 方法中,我正在构建GoogleApiClient 对象:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
2) 在onStart(),我打电话给mGoogleApiClient.connect()。
3) 我的活动实现 ConnectionCallbacks 和 OnConnectionFailedListener.
4) 我的onConnectionFailed() 方法如下所示:
public void onConnectionFailed(ConnectionResult result) {
//in dubug result looks like : ConnectionResult{
//statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent
// {41f8ca70: android.os.BinderProxy@41f8ca10}}
try {
if(!mIntentInProgress && result.hasResolution())
{
mIntentInProgress=true;
result.startResolutionForResult(mActivity, RC_SIGN_IN);
}
} catch (SendIntentException e) {
e.printStackTrace();
}
}
5) 我的onActivityResult() 方法包含:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
当我运行我的应用程序时,我得到一个 Toast 表示弹出了一个内部错误。我确实在 Google 控制台中创建了该项目。
【问题讨论】:
标签: android google-play google-play-services