无法登录到Google游戏服务

时间:2018-10-16 15:28:33

标签: android google-play-games

我正在用android O编写一个简单的应用程序,并希望连接到Google游戏服务以使用实时游戏服务。

我已经阅读了文档,但是找不到任何错误。

我在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();
            }
        }

    }

由于某种原因,我不明白,我没有获得任何形式的登录视图或消息(我认为那是应该发生的事情),并且得到的空符号结果会转换为消息“登录错误”。

我已在play.google.publish中添加了用于游戏服务测试的应用程序,该用户被添加为测试用户。

我在这里关注了文档:https://developers.google.com/games/services/android/signin

1 个答案:

答案 0 :(得分:1)

我没有按如下所述将应用程序ID添加到manifiedt文件中:https://developers.google.com/games/services/android/quickstart#step_3_modify_your_code