好的,所以我将在此处发布我是如何设置的,使用 LibGDX 和 GPGS,并且在注销后登录时显示弹出窗口没有任何问题。
首先是我对我的 Android 项目的声明:
public class MainActivity extends AndroidApplication implements RequestHandler, GameHelperListener,
GoogleInterface, RealTimeMessageReceivedListener, RoomStatusUpdateListener, RoomUpdateListener,
OnInvitationReceivedListener, RealTimeReliableMessageSentListener, OnImageLoadedListener, OnStateLoadedListener, ConnectionCallbacks{
private GameHelper mHelper;
private GameHelperInterface mGHInterface = null;
private ConfirmInterface mConfirmInterface = null;
private Handler libGDXHandler;
GoogleInterface 用于从 LibGDX 线程传递到 Android 线程,GameHelperInterface 和 ConfirmInterface 用于将事物从 android 传递到房子的 libGDX 端(我使用 confirmInteface 登录东西,另一个用于消息传递,等等......)处理程序是为了确保来自 LibGDX 端的任何内容都正确发布到 Android 线程上(就像来自 Android 的 libGDX 端的任何内容都使用 Gdx.app.postRunnable() 发布)
现在我在 onCreate() 中声明
.. setup the gameView etc..
mHelper.setup(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_PLUS, null);
mHelper.getPlusClient().registerConnectionCallbacks(this);
onStart 和 onStop :
@Override
public void onStart(){
super.onStart();
mHelper.onStart(this);
}
@Override
public void onStop(){
super.onStop();
mHelper.onStop();
}
Android 代码中的 Login 和 Logout 方法
@Override
public void Login() {
libGDXHandler.post(new Runnable() {
@Override
public void run() {
dLog("beginUserInitatedSignIn()");
//mHelper.signOut();
mHelper.beginUserInitiatedSignIn();
}
});
}
@Override
public void LogOut() {
iServerBadAttempts = -1;
mHelper.signOut();
}
使用 iServerBadAttempts 以便当我在 libGDX 中启动 Screen 进程时,我可以要求 Android 端给我该变量...如果它是 -1,那么我知道之前没有尝试过登录,并且可以设置我的谷歌登录按钮适当,否则我检查连接状态和其他几件事来设置我使用的按钮。
为了以防万一,下面是我告诉我的 libGDX 代码 mHelper 成功登录的方式:
@Override
public void onSignInSucceeded() {
dLog("signed in");
mConfirmInterface.googleSucceeded();
if (mHelper.getInvitationId() != null) {
acceptInviteToRoom(mHelper.getInvitationId());
mConfirmInterface.acceptedInvitation();
}
}
这是登录和注销的logcat
09-24 09:14:31.495: I/SplashScreen(6021): 做谷歌登录 09-24 09:14:31.495: D/LDGame MainActivity(6021): beginUserInitatedSignIn() 09-24 09:14:31.495: D/ Helper(6021):启动 USER-INITIATED 登录流程。09-24 09:14:31.495: D/Helper(6021): isGooglePlayServicesAvailable 返回 0 09-24 09:14:31.495: D/Helper(6021): beginUserInitiatedSignIn: 开始新的登录流程。09-24 09:14:31.495:D/Helper(6021):开始连接。09-24 09:14:31.495:D/Helper(6021):状态更改 DISCONNECTED -> CONNECTING 09-24 09:14:31.495:D/Helper(6021):connectNextClient:请求的客户端:7,连接的客户端:0 09 -24 09:14:31.495:D/Helper(6021):待定客户端:7 09-24 09:14:31.495:D/Helper(6021):连接 GamesClient。09-24 09:14:31.535:D/Helper(6021):onConnectionFailed 09-24 09:14:31.535:D/Helper(6021):连接失败:09-24 09:14:31.535:D/Helper(6021):-代码:SIGN_IN_REQUIRED(4) 09-24 09:14:31.535:D/Helper(6021):-可解析:真 09-24 09:14: 31.535:D/Helper(6021):-详细信息:ConnectionResult{statusCode=SIGN_IN_REQUIRED,分辨率=PendingIntent{41d914d0:android.os.BinderProxy@41ef40c8}} 09-24 09:14:31.535:D/Helper(6021):onConnectionFailed :由于用户启动登录,解决问题。09-24 09:14:31.535: D/Helper(6021): resolveConnectionResult: 试图解决结果: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{41d914d0: android.os.BinderProxy@41ef40c8}} 09-24 09:14 :31.535: D/Helper(6021): 结果有分辨率。启动它。09-24 09:14:31.615:I/ScreenLog(6021):屏幕暂停:SplashScreen 09-24 09:14:31.615:D/SensorManager(6021):unregisterListener::Listener=com.badlogic.gdx.backends。传感器侦听器拆除 09-24 09:14:32.220:W/IInputConnectionWrapper(6021):非活动 InputConnection 上的 showStatusIcon 09-24 09:14:37.010:D/Helper(6021):onActivityResult:req=RC_RESOLVE,resp=RESULT_OK 09 -24 09:14:37.010:D/Helper(6021):onAR:分辨率为 RESULT_OK,因此再次连接当前客户端。09-24 09:14:37.065: D/LDGame MainActivity(6021): on Activity 结果 09-24 09:14:37.065: D/SensorManager(6021): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay = 20000 Listener= com.badlogic.gdx.backends.android.AndroidInput$SensorListener@41ef6c38 09-24 09:14:37.070: D/SensorManager(6021): registerListener :: handle = 1 name= AK8975C 3 轴磁场传感器延迟= 20000 侦听器= com.badlogic.gdx.backends.android.AndroidInput$SensorListener@41ef6f00 09-24 09:14:37.070: I/AndroidInput(6021): 传感器侦听器设置 09-24 09:14:37.100:I/ScreenLog(6021):屏幕调整大小:SplashScreen 09-24 09:14:37.100:I/ScreenLog(6021):屏幕恢复:SplashScreen 09-24 09:14: 37.160: D/dalvikvm(6021): GC_CONCURRENT 释放 674K, 13% 空闲 13233K/15047K, 暂停 7ms+3ms, 总共 61ms 09-24 09:14:37.160: D/dalvikvm(6021): WAIT_FOR_CONCURRENT_GC 阻塞 22ms 09-2 :14:37.180: D/dalvikvm(6021): GC_FOR_ALLOC 释放 10K, 13% 释放 13222K/15047K, 暂停 18ms, 共 18ms 09-24 09:14:37.180: I/dalvikvm-heap(6021): Grow heap (frag case) 到 13.932MB 分配 313374 字节 09-24 09:14:37.200: D/dalvikvm(6021): GC_FOR_ALLOC freed <1K, 12% free 13528K/15367K, paused 19ms, total 19ms 09-24 09:14: 37.235: D/SensorManager(6021): onAccuracyChanged :: 精度 = 3 09-24 09:14:37.240: D/Helper(6021): onConnected: 已连接!客户=1 09-24 09:14:37.240: D/Helper(6021):连接的客户端更新为:1 09-24 09:14:37.240:D/Helper(6021):connectNextClient:请求的客户端:7,连接的客户端:1 09-24 09:14:37.240:D /Helper(6021):待定客户端:6 09-24 09:14:37.240:D/Helper(6021):连接 PlusClient。09-24 09:14:37.395: D/dalvikvm(6021): GC_FOR_ALLOC 释放 511K, 14% 空闲 13236K/15367K, 暂停 20ms, 总共 20ms 09-24 09:14:37.570: D/dalvikvm(6021): GC_CONCURRENT 释放320K, 14% free 13319K/15367K, paused 1ms+1ms, total 34ms 09-24 09:14:37.755: D/dalvikvm(6021): GC_CONCURRENT freed 482K, 14% free 13295K/15367K, paused 12ms+2ms,总共33ms 09-24 09:14:37.840: I/AndroidGraphics(6021): 恢复 09-24 09:14:38.055: D/Helper(6021): onConnected: 已连接!客户端 = 2 09-24 09:14:38.055:D/Helper(6021):连接的客户端更新为:3 09-24 09:14:38.055:D/Helper(6021):connectNextClient:请求的客户端:7,连接的客户端:3 09-24 09:14:38.055:D/Helper(6021):待定客户端:4 09-24 09:14:38.055:D/Helper(6021):连接 AppStateClient。09-24 09:14:38.070:D/LDGame MainActivity(6021):内部连接 09-24 09:14:38.070:D/LDGame MainActivity(6021):数字 09-24 09:14:38.090:D/Helper (6021):onConnected:已连接!客户端 = 4 09-24 09:14:38.090:D/Helper(6021):连接的客户端更新为:7 09-24 09:14:38.090:D/Helper(6021):connectNextClient:请求的客户端:7,连接的客户端:7 09-24 09:14:38.090:D/Helper(6021):待定客户端:0 09-24 09:14:38.090:D/Helper(6021):所有客户端现已连接。登录成功!09-24 09:14:38.090:D/Helper(6021):所有请求的客户端都已连接。登录成功!09-24 09:14:38.090: D/Helper(6021): 状态改变连接->
对于登录,重点是您应该看到“D/Helper(6021):onConnectionFailed:因为用户启动登录,正在解决问题。” 因为这意味着注销以前有效
并退出 logcat
09-24 09:14:52.145:D/Helper(6021):清除 PlusClient 上的默认帐户。09-24 09:14:52.165:D/Helper(6021):从 GamesClient 注销。09-24 09:14:52.190:D/Helper(6021):继续断开连接。09-24 09:14:52.190:D/Helper(6021):killConnections:杀死连接。09-24 09:14:52.190:D/Helper(6021):断开 GamesClient。09-24 09:14:52.195:D/Helper(6021):断开 PlusClient。09-24 09:14:52.195:D/Helper(6021):断开 AppStateClient。09-24 09:14:52.195:D/Helper(6021):killConnections:所有客户端断开连接。09-24 09:14:52.195: D/Helper(6021): 状态改变 CONNECTED -> DISCONNECTED
希望有帮助!