GooglePlay排行榜

作者: Zi_Fi | 来源:发表于2019-01-28 18:27 被阅读0次

    GooglePlay排行榜

        // 排行榜
        private static final String TAG = "GFB";
        private static AppActivity this_tmp;
        //登录google账号
        public static void loginGameCenter() {
            Log.d(TAG, "signInSilently()");
    
            if(!isSignedIn())
                startSignInIntent();
            else {
                GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this_tmp,
                        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());
                mGoogleSignInClient.silentSignIn().addOnCompleteListener(this_tmp,
                        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());
                                }
                            }
                        });
            }
        }
    
        //提交分数到排行榜
        public static void uploadScore(String leaderboard_id,int value){
            if(!isSignedIn())
                return;
            Games.getLeaderboardsClient(this_tmp, GoogleSignIn.getLastSignedInAccount(this_tmp))
                    .submitScore(leaderboard_id, value);
        }
    
        //显示排行榜
        public static void showLeaderboard(String leaderboard_id){
            Games.getLeaderboardsClient(this_tmp, GoogleSignIn.getLastSignedInAccount(this_tmp))
                    .getLeaderboardIntent(leaderboard_id)
                    .addOnSuccessListener(new OnSuccessListener<Intent>() {
                        @Override
                        public  void onSuccess(Intent intent) {
                            this_tmp.startActivityForResult(intent, 9004);
                        }
                    });
        }
    
        //排行榜分数
        private static int score;
        //得到排行榜数据
        public static void getScoreData(String leaderboard_id){
            if(!isSignedIn())
                return;
            Games.getLeaderboardsClient(this_tmp, GoogleSignIn.getLastSignedInAccount(this_tmp))
                    .loadCurrentPlayerLeaderboardScore(
                            leaderboard_id, LeaderboardVariant.TIME_SPAN_ALL_TIME,
                            LeaderboardVariant.COLLECTION_PUBLIC)
                    .addOnSuccessListener(this_tmp, new OnSuccessListener<AnnotatedData<LeaderboardScore>>(){
                                public long score_tmp;
                                @Override
                                public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
                                    if (leaderboardScoreAnnotatedData != null) {
                                        if (leaderboardScoreAnnotatedData.get() != null) {
                                            score_tmp = leaderboardScoreAnnotatedData.get().getRawScore();
                                            score = (int) score_tmp;
                                            Log.d(TAG,"score_tmp"+String.valueOf(score));
                                        }
                                    }
                                }
                            }
                    );
        }
    
        //得到排行榜分数
        public static int getScore()
        {
            Log.d(TAG,"score"+String.valueOf(score));
            return score;
        }
        private static final int RC_SIGN_IN = 9001;
        private static void startSignInIntent() {
            GoogleSignInClient signInClient = GoogleSignIn.getClient(this_tmp,
                    GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
            Intent intent = signInClient.getSignInIntent();
            this_tmp.startActivityForResult(intent, RC_SIGN_IN);
        }
        private static boolean isSignedIn() {
            return GoogleSignIn.getLastSignedInAccount(this_tmp) != null;
        }
    

    GooglePlayConsole后台设置


    1.jpg 2.jpg Snipaste_2018-08-14_12-08-06.jpg Snipaste_2018-08-14_12-08-27.jpg Snipaste_2018-08-14_12-10-33.jpg Snipaste_2018-08-14_14-07-35.jpg Snipaste_2018-08-14_14-10-53.jpg Snipaste_2018-08-14_14-13-05.jpg Snipaste_2018-08-14_14-15-09.jpg Snipaste_2018-08-14_14-16-41.jpg Snipaste_2018-08-14_14-17-15.jpg Snipaste_2018-08-14_14-21-37.jpg Snipaste_2018-08-14_14-22-51.jpg Snipaste_2018-08-14_14-28-28.jpg Snipaste_2018-08-14_14-29-09.jpg Snipaste_2018-08-14_14-32-11.jpg Snipaste_2018-08-14_14-33-22.jpg Snipaste_2018-08-14_14-36-51.jpg Snipaste_2018-08-14_14-53-41.jpg Snipaste_2018-08-14_15-14-24.jpg Snipaste_2018-08-14_15-20-59.jpg

    相关文章

      网友评论

        本文标题:GooglePlay排行榜

        本文链接:https://www.haomeiwen.com/subject/msczjqtx.html