如何实施Google Play服务?

时间:2019-11-12 22:38:09

标签: java android google-play-services

我正在为乐趣开发一个Android应用程序,但自3天以来就被屏蔽了。 我已经实现了排行榜Google,但是当我玩游戏时,该分数并未在Google的开发人员控制台上更新。 当我想要显示LeaderBoard时未显示。我有排行榜的名称,但上面写着“在Play游戏中发生错误” 有帮助吗?

我更新游戏活动得分的方法,在调试模式下,我通过了“ if(score ...”:

 private void updateLeaderboards(int score) {
    if (!isSignedIn()) {
        return;
    }

    if (score>= 0 )  {
        Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this))
                .submitScore(getString(R.string.leaderboard_hall_of_fame), score);
    }
}

我显示排行榜的方法:

  public void onShowLeaderboardsRequested(View v) {
    if (!isSignedIn()) {
        signInOptions =
                new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                        .requestEmail()
                        .requestProfile()
                        .build();

        // Create the client used to sign in to Google services.
        mGoogleSignInClient = GoogleSignIn.getClient(this,
                signInOptions);

        startSignInIntent();
    }
    else {
        Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this))
                .getLeaderboardIntent(getString(R.string.leaderboard_hall_of_fame))
                .addOnSuccessListener(new OnSuccessListener<Intent>() {
                    @Override
                    public void onSuccess(Intent intent) {
                        startActivityForResult(intent, RC_LEADERBOARD_UI);
                    }
                });
    }

}

leaderboard_hall_of_fame,app_id和package_name在games-ids.xml中定义。

我在build.gradle中的依赖项:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.4'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-games:18.0.1'
implementation 'com.google.android.gms:play-services-auth:17.0.0'

}

谢谢! 对不起,我的英语

0 个答案:

没有答案