gpt4 book ai didi

android - Android 4 上的 Google+ 登录错误,statusCode=SIGN_IN_REQUIRED

转载 作者:太空宇宙 更新时间:2023-11-03 10:19:10 25 4
gpt4 key购买 nike

我的目标是开发一款可以与 friend 一起测试音乐的游戏。您可以通过注册到这个 Google+ 社区来自己测试它: https://plus.google.com/u/0/communities/100815426127955231967

我正在多个设备上测试我的应用:

  • 摩托罗拉 Xoom,安卓 4.1.2,构建 JZO54K
  • Nexus 7 2012 Wifi“nagasi”,android 5.0.2,build LRX22G
  • Nexus 5,android 5.0.1,构建 LRX22C

我在所有设备上使用同一个 Google 用户。我的应用程序已注册,并且我在 list 文件中包含了正确的行。

使用完全相同的代码,我可以在 Nexus 7 和 Nexus 5 lollipop 设备上成功连接到 Google Plus 和游戏服务,但不能在 Xoom android 4 设备上连接。

这是代码,连接请求在 Activity onCreate 中:

@Override
protected void onCreate(Bundle savedInstanceState) {
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
if (mGoogleApiClient == null) {
Plus.PlusOptions plusOptions = new Plus.PlusOptions.Builder().addActivityTypes(
"http://schemas.google.com/AddActivity", "http://schemas.google.com/ReviewActivity").build();
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Plus.API, plusOptions).addScope(Plus.SCOPE_PLUS_LOGIN)
.addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
}
mGoogleApiClient.connect();
} else {
Toast.makeText(this, R.string.texteErreurGPlus, Toast.LENGTH_LONG).show();
}
}

对于 Android 4 设备,调用 onConnectionFailed 回调并显示一条消息:

GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{412f07c8: android.os.BinderProxy@413b0bd0}} :


@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingConnectionFailure) {
// Already resolving
return;
} else if (result.hasResolution()) {
try {
mResolvingConnectionFailure = true;
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingConnectionFailure = true;
}
}

这导致 Activity onActivityResult :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
mResolvingConnectionFailure = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
} else {
mGoogleApiClient.connect();
}
break;

和无限循环,因为 resultCode 不等于 RESULT_OK。

这是 Android Studio 的 gradle 文件:

apply plugin: 'android'

android {
compileSdkVersion 21
buildToolsVersion '21.1.2'

defaultConfig {
applicationId "debut.blindtest"
minSdkVersion 16
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile project(':volley')
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.google.android.gms:play-services-plus:6.5.+'
compile 'com.google.android.gms:play-services-games:6.5.+'
compile files('libs/deezer-sdk-0.10.16.jar')
}

执行流程是:

  • 调用 GoogleApiClient 连接的主要 Activity onCreate
  • 调用了主 Activity onConnectionFailed,结果有解析,因此调用了 result.startResolutionForResult
  • 主 Activity onActivityResult 被调用

异常:

01-07 22:38:01.260    4894-4894/debut.blindtest I/TagApplicationBlindTest﹕ onActivityResult : REQUEST_CODE_RESOLUTION : resultCode : 0  
01-07 22:38:01.280 4935-4936/? D/dalvikvm﹕ GC_CONCURRENT freed 448K, 7% free 6800K/7303K, paused 24ms+3ms, total 55ms
01-07 22:38:01.280 4935-4935/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 22ms
01-07 22:38:01.280 4894-4894/debut.blindtest E/BaseGamesUtils﹕ No standard error dialog available. Making fallback dialog.
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/app/SharedElementCallback;)
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.setEnterSharedElementCallback, referenced from method android.support.v4.app.q.setEnterSharedElementCallback
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 80: Landroid/app/Activity;.setEnterSharedElementCallback (Landroid/app/SharedElementCallback;)V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/app/SharedElementCallback;)
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.setExitSharedElementCallback, referenced from method android.support.v4.app.q.setExitSharedElementCallback
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 81: Landroid/app/Activity;.setExitSharedElementCallback (Landroid/app/SharedElementCallback;)V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.finishAfterTransition, referenced from method android.support.v4.app.q.supportFinishAfterTransition
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 46: Landroid/app/Activity;.finishAfterTransition ()V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.postponeEnterTransition, referenced from method android.support.v4.app.q.supportPostponeEnterTransition
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 77: Landroid/app/Activity;.postponeEnterTransition ()V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.startPostponedEnterTransition, referenced from method android.support.v4.app.q.supportStartPostponedEnterTransition
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 89: Landroid/app/Activity;.startPostponedEnterTransition ()V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
01-07 22:38:01.410 4894-4898/debut.blindtest D/dalvikvm﹕ GC_CONCURRENT freed 325K, 6% free 7193K/7623K, paused 14ms+38ms, total 115ms
01-07 22:38:01.410 4935-4936/? D/dalvikvm﹕ GC_CONCURRENT freed 460K, 8% free 6851K/7367K, paused 19ms+12ms, total 83ms
01-07 22:38:01.410 4935-4935/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 41ms
01-07 22:38:01.450 4864-4864/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.util.e.a
01-07 22:38:01.450 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve check-cast 35 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/util/e;
01-07 22:38:01.450 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x0010
01-07 22:38:01.460 4864-4864/? E/SignInActivity﹕ SignInActivity must be started with startActivityForResult
01-07 22:38:01.530 4935-4936/? D/dalvikvm﹕ GC_CONCURRENT freed 457K, 7% free 6916K/7431K, paused 18ms+5ms, total 61ms

你能帮我看看我应该怎么做才能与 Android 4 设备兼容吗?

最佳答案

通过在 onConnectionFailed() 中自动连接,您将根据需要继续尝试连接多次,直到获得有效连接,如您所见。这意味着即使用户不想登录(例如,他们在登录对话框中点击取消),他们也会不断地被提示一遍又一遍。

相反,Google+ Sign In guide , 使用 mSignInClicked 变量来帮助确定 onConnectionFailed() 是否应该立即重新连接(对于未连接的人来说,理想情况是 onConnectionFailed() 被已调用但您尚未调用 startResolutionForResult() - 只需保存 ConnectionResult 直到用户登录)。

如果您想保持初始自动登录尝试,您可以考虑在 Google Play Games Services samples 中使用的方法例如TrivialQuest他们的 onConnnectionFailed() 方法如下所示:

public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed() called, result: " + connectionResult);

if (mResolvingConnectionFailure) {
Log.d(TAG, "onConnectionFailed() ignoring connection failure; already resolving.");
return;
}

if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = BaseGameUtils.resolveConnectionFailure(this,
mGoogleApiClient, connectionResult, RC_SIGN_IN,
getString(R.string.signin_other_error));
}
showSignInBar();
}

他们在哪里使用 BaseGameUtils使连接到 Google 服务变得更加容易的辅助方法(注意:其中没有任何内容与游戏服务特别相关 - 它同样适用于所有 GoogleApiClient 连接)。

关于android - Android 4 上的 Google+ 登录错误,statusCode=SIGN_IN_REQUIRED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27770243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com