Java 使用Google Play服务登录Libgdx
所以我不太确定如何使用libgdx处理GooglePlay服务登录,我的意思是我想在应用程序开始时请求用户登录。所以我的第一次尝试是在Java 使用Google Play服务登录Libgdx,java,libgdx,google-play-services,Java,Libgdx,Google Play Services,所以我不太确定如何使用libgdx处理GooglePlay服务登录,我的意思是我想在应用程序开始时请求用户登录。所以我的第一次尝试是在AndroidLauncher的onCreate方法中实现如下登录 protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setRequestedOrientation(ActivityInfo.S
AndroidLauncher
的onCreate
方法中实现如下登录
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startSignInIntent();
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MainGame(this), config);
}
起初,它看起来工作正常,第一次打开它要求我登录的应用程序,然后在下一个应用程序中打开它却没有。但这里的问题是,无论启动Signingent
是否成功,都会调用初始化
方法,我想让它仅在登录成功时调用初始化
,如果失败,可能会关闭应用程序,并让用户通过再次打开我的应用程序重试。我试图在OnActivityResult
中的result.issucess()
中调用initialize,但它不起作用,我想它必须在onCreate中调用
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if(result.isSuccess()) {
userAccount = result.getSignInAccount();
Log.i("GoogleAccountTest", "Login Successful");
} else {
String message = result.getStatus().getStatusMessage();
if(message == null || message.isEmpty()) {
message = "Something went wrong";
}
new AlertDialog.Builder(this).setMessage(message).setNeutralButton("Ok", null).show();
}
}
}
然后我试着用一个按钮创建自己的登录屏幕来登录google,我创建了一个界面,在AndroidLauncher
中实现了它,并将它传递给我的初始化方法,然后调用.startSigningent()
,但问题是我仍然无法理解调用是否成功
在这种情况下,我应该如何实现Google Play Services登录?好的,几天后如果有人想知道我是如何处理的,这就是我的解决方案:
我用登录按钮创建了额外的屏幕,我在按下按钮时调用startsignient
,然后在主活动中创建了一个标志,当startsignient
结果成功时,我在onActivityResult
中将其设置为true。然后,在带有“渲染方法”中的“登录”按钮的屏幕中,我检查该标志,当它变为“真”时,我将屏幕更改为“主菜单”