我正在 android O 中编写一个简单的应用程序,并且想连接到谷歌游戏服务以使用实时游戏服务。
我已经浏览了文档,但找不到任何错误。
我在 xml 上有一个按钮来激活登录:
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/goButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
在 onCreate 上我有这个:
mGoogleSignInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
findViewById(R.id.sign_in_button).setOnClickListener(this);
然后在点击监听器上:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
Log.d("MainActivity", "Sign-in button clicked");
clickedSignIn(v);
break;
...
...
}
public void clickedSignIn(View view) {
Log.d("MainActivity","clickedSignIn");
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
onConnected(account);
} catch (ApiException apiException) {
String message = apiException.getMessage();
if (message == null || message.isEmpty()) {
message = "Unknown error on sign-in.";
}
onDisconnected();
new AlertDialog.Builder(this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show();
}
}
}
出于某种我不明白的原因,我没有得到任何类型的登录 View 或消息(我认为这是应该发生的),并且得到一个空的登录结果,它转换为消息“登录错误”。
我在 play.google.publish 的游戏服务中添加了用于测试的应用程序,该用户被添加为测试用户。
我遵循了此处的文档:https://developers.google.com/games/services/android/signin
最佳答案
我没有按照此处所述将应用程序 ID 添加到 list 文件:https://developers.google.com/games/services/android/quickstart#step_3_modify_your_code
关于android - 无法登录谷歌游戏服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52839016/