问题描述
我正在开发一个想要使用 Google API 的 Android 应用程序.为此,我导入了 google-play-service-lib 项目.
我正在关注这个 链接 来初始化 GoogleApiClient 对象.p>
我的代码:
1) 在 onCreate()
方法中,我正在构建 GoogleApiClient 对象:
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(这个).addOnConnectionFailedListener(这个).addApi(Plus.API, null).addScope(Plus.SCOPE_PLUS_LOGIN).建造();
2) 在onStart()
中,我调用mGoogleApiClient.connect()
.
3) 我的活动实现ConnectionCallbacks 和 OnConnectionFailedListener.
4) 我的 onConnectionFailed()
方法如下所示:
public void onConnectionFailed(ConnectionResult 结果) {//在 dubug 结果中看起来像:ConnectionResult{//statusCode=SIGN_IN_REQUIRED,分辨率=PendingIntent//{41f8ca70: android.os.BinderProxy@41f8ca10}}尝试 {if(!mIntentInProgress && result.hasResolution()){mIntentInProgress=true;result.startResolutionForResult(mActivity, RC_SIGN_IN);}} 捕捉(SendIntentException e){e.printStackTrace();}}
5) 我的 onActivityResult()
方法包含:
if (requestCode == RC_SIGN_IN) {if (!mGoogleApiClient.isConnecting()) {mGoogleApiClient.connect();}}
当我运行我的应用程序时,我得到一个 Toast 表示弹出了一个内部错误.我确实在 Google 控制台中创建了该项目.
我也遇到了同样的问题.
来自文档:客户端可以选择不使用 API 继续,也可以调用 startResolutionForResult(Activity, int) 提示用户登录.
所以你应该尝试使用 startResolutionForResult() 函数登录
@Override公共无效onConnectionFailed(连接结果结果){if (result.hasResolution()) {尝试 {//!!!result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);} 捕捉(SendIntentException e){mPlusClient.connect();}}mConnectionResult = 结果;}
I am developing an Android application where I want to use the Google API. For that I have imported the google-play-service-lib project.
I am following this link to initialize GoogleApiClient object.
My code:
1) In the onCreate()
method I am building the GoogleApiClient object:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
2) In onStart()
, I call mGoogleApiClient.connect()
.
3) My activity implements ConnectionCallbacks and OnConnectionFailedListener.
4) My onConnectionFailed()
method looks like:
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()
method contains:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
When I run my app I get a Toast that says that an internal error popped up. I did create the project in the Google console.
I had the same problem.
From documentation: The client may choose to continue without using the API or it may call startResolutionForResult(Activity, int) to prompt the user to sign in.
So you should try to sign in by using startResolutionForResult() function
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
// !!!
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
mConnectionResult = result;
}
这篇关于onConnectionFailed 给 SIGN_IN_REQUIRED(4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!