android - 无法登录谷歌游戏服务

标签 android google-play-games

我正在 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/

相关文章:

android - 当应用程序处于前台时避免通知弹出窗口

android - Crashlytics(Android)在下次崩溃前清除日志

android - 列出 Google Play 游戏服务中的所有排行榜

android - 如何更改 SearchView 上的默认图标,以便在 Android 的操作栏中使用?

android - 如何在安卓浏览器中播放直播视频?

android - 使用 Android 实时多人游戏时应用程序版本之间的消息兼容性

android - Google Play 游戏服务登录错误 : ApiException :4

安卓 :What is the difference between app signing certificate and upload certificate?

javascript - 始终登录我的 android 和 ios 移动应用程序

android - 保存的游戏快照初始化(空对象引用)