GooglePlay新版排行榜接入

Posted txfd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GooglePlay新版排行榜接入相关的知识,希望对你有一定的参考价值。

新版本的GMS的api和老版本的有很大的差异,刚接了一下,在这里留一个记号,以便查阅:
判定是否已经登录

private static boolean isSignedIn(Cocos2dxActivity cocos2dxActivity) 
    return GoogleSignIn.getLastSignedInAccount(cocos2dxActivity) != null;

登录GameCenter

public static void loginGameCenter(Cocos2dxActivity cocos2dxActivity) 
    Log.d(TAG, "signInSilently()");
    mGoogleSignInClient = GoogleSignIn.getClient(cocos2dxActivity,
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());

    if(!isSignedIn(cocos2dxActivity))
        startSignInIntent(cocos2dxActivity);
    
    else 
//静默登录
        mGoogleSignInClient.silentSignIn().addOnCompleteListener(cocos2dxActivity,
                new OnCompleteListener<GoogleSignInAccount>() 
                    @Override
                    public void onComplete(@NonNull Task<GoogleSignInAccount> task) 
                        if (task.isSuccessful()) 
                            Log.d(TAG, "signInSilently(): success");
                         else 
                            Log.d(TAG, "signInSilently(): failure", task.getException());
                        
                    
                );
    

登录按钮点击之后调用:

private static void startSignInIntent(Cocos2dxActivity cocos2dxActivity) 
    GoogleSignInClient signInClient = GoogleSignIn.getClient(cocos2dxActivity,
            GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    Intent intent = signInClient.getSignInIntent();
    cocos2dxActivity.startActivityForResult(intent, RC_SIGN_IN);

提交分数到排行榜

public static void uploadScore(String leaderboard_id,long value,Cocos2dxActivity cocos2dxActivity)
    if(!isSignedIn(cocos2dxActivity))
        return;
    
    Games.getLeaderboardsClient(cocos2dxActivity, GoogleSignIn.getLastSignedInAccount(cocos2dxActivity))
            .submitScore(leaderboard_id, value);

//显示排行榜

public static void showLeaderboard(String leaderboard_id, final Cocos2dxActivity cocos2dxActivity)
    Games.getLeaderboardsClient(cocos2dxActivity, GoogleSignIn.getLastSignedInAccount(cocos2dxActivity))
            .getLeaderboardIntent(leaderboard_id)
            .addOnSuccessListener(new OnSuccessListener<Intent>() 
                @Override
                public  void onSuccess(Intent intent) 
                    cocos2dxActivity.startActivityForResult(intent, 9004);
                
            );

参考

https://developers.google.cn/identity/sign-in/android/?hl=zh-cn

以上是关于GooglePlay新版排行榜接入的主要内容,如果未能解决你的问题,请参考以下文章

在 Google Play 游戏中查看应用的排行榜

Google Play 商店中未显示排行榜和成就徽章

google play 游戏是不是支持排名匹配和排行榜?

实例:Google Play游戏服务接入排行榜和成就系统

在 Codemagic 中禁用 Google Play 发布

怎么接入google play支付