• 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

  • 相关阅读:
    centos 新增用户, 然后他在主目录添加网站403Forbbiden
    linux 把用户加入一个组&从这个组中移除
    [THINKPHP] 温故知新之getFieldBy
    php 获取指定月份的开始结束时间
    apache 占用内存总量与每个apache进程的平均内存占用量计算
    网站并发300就很慢
    centos定时备份数据库超简单示例
    php导出excel时间错误(同一个时间戳,用date得到不同的时间)
    设置iframe 载入页面的效果跟直接打开这个页面一样
    node基础09:第2个node web服务器
  • 原文地址:https://www.cnblogs.com/txfd/p/11193902.html
Copyright © 2020-2023  润新知