我正在开发一个 Android 应用程序,我想在其中使用 Google API。为此我导入了谷歌播放服务库项目。
我正在关注这个link https://developers.google.com/+/mobile/android/getting-started初始化 GoogleApiClient 对象。
My code:
1)在onCreate()
我正在构建的方法谷歌API客户端 object:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
2) In onStart()
, 我打电话mGoogleApiClient.connect()
.
3)我的活动实施连接回调 and OnConnectionFailedListener。
4) My 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) My onActivityResult()
方法包含:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
当我运行我的应用程序时,我得到一个Toast这表明出现了内部错误。我确实在 Google 控制台中创建了该项目。