【问题标题】:Google Play Service Leaderboard Continuously Popping UpGoogle Play 服务排行榜不断弹出
【发布时间】:2014-05-20 11:58:10
【问题描述】:

我一直在尝试控制何时弹出 Google Play 排行榜登录,以及一旦用户登录 Google Play 服务排行榜在启动时和恢复后弹出。我该怎么做?我扩展了 BaseGameActivity 并在下面实现以显示排行榜

 if (isSignedIn()) {
        startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
                RC_UNUSED);

public int gameMode;

public static void showLeaderboard(int mode) {
    me.gameMode = mode;
    me.runOnUiThread(new Runnable() {
        public void run() {
            if (me.isSignedIn())
                me.onShowLeaderboard();
            else
                me.SignIn();
        }
    });
}

public static void submitScore(final int score) {
    me.gameMode = score / 1000000;
    me.runOnUiThread(new Runnable() {
        public void run() {
            me.onSubmitScore(score % 1000000);
        }
    });

}


   public void onShowLeaderboard() {
    if (isSignedIn()) {
        startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
                RC_UNUSED);
    } else {
        showAlert(getString(R.string.signing_in));
        this.SignIn();
    }
}

public void onSubmitScore(int score) {
    if (isSignedIn()) {
        switch (gameMode) {
        case 1:
            getGamesClient().submitScore(getString(R.string.leaderboard1),
                    score);
            break;
        case 2:
            getGamesClient().submitScore(getString(R.string.leaderboard2),
                    score);
            break;
        case 3:
            getGamesClient().submitScore(getString(R.string.leaderboard3),
                    score);
            break;
        }
    } else {
        showAlert(getString(R.string.signing_in));
        this.SignIn();
    }
}

boolean verifyPlaceholderIdsReplaced() {
    final boolean CHECK_PKGNAME = true; // set to false to disable check
                                        // (not recommended!)

    // Did the developer forget to change the package name?
    if (CHECK_PKGNAME && getPackageName().startsWith("com.google.example.")) {
        Log.e(TAG,
                "*** Sample setup problem: "
                        + "package name cannot be com.google.example.*. Use your own "
                        + "package name.");
        return false;
    }

    // Did the developer forget to replace a placeholder ID?
    // int res_ids[] = new int[] {
    // R.string.app_id
    // };
    // for (int i : res_ids) {
    // if (getString(i).equalsIgnoreCase("ReplaceMe")) {
    // Log.e(TAG, "*** Sample setup problem: You must replace all " +
    // "placeholder IDs in the ids.xml file by your project's IDs.");
    // return false;
    // }
    // }
    return true;
}

public void SignIn() {
    if (!verifyPlaceholderIdsReplaced()) {
        showAlert("Sample not set up correctly. See README.");
        return;
    }

    // start the sign-in flow
    beginUserInitiatedSignIn();
}

@Override
public void onSignInFailed() {
    System.out.println("SignIn Failed!");
    // Intent mainIntent = new Intent(FirstActivity.this,
    // FlappyBirdActivity.class);
    // FirstActivity.this.startActivity(mainIntent);
    // FirstActivity.this.finish();
}

@Override
public void onSignInSucceeded() {
    System.out.println("SignIn Successed!");
    onShowLeaderboard();
}

【问题讨论】:

    标签: android google-play-services


    【解决方案1】:

    已解决我一直在尝试控制何时弹出 Google Play 排行榜登录,以及一旦用户登录 Google Play 服务排行榜在启动时和恢复后弹出。我该怎么做?我扩展了 BaseGameActivity 并在下面实现以显示排行榜

    if (isSignedIn()) {
            startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
                    RC_UNUSED);
    public int gameMode;
    
    public static void showLeaderboard(int mode) {
        me.gameMode = mode;
        me.runOnUiThread(new Runnable() {
            public void run() {
                if (me.isSignedIn())
                    me.onShowLeaderboard();
                else
                    me.SignIn();
            }
        });
    }
    
    public static void submitScore(final int score) {
        me.gameMode = score / 1000000;
        me.runOnUiThread(new Runnable() {
            public void run() {
                me.onSubmitScore(score % 1000000);
            }
        });
    
    }
    
    
       public void onShowLeaderboard() {
        if (isSignedIn()) {
            startActivityForResult(getGamesClient().getAllLeaderboardsIntent(),
                    RC_UNUSED);
        } else {
            showAlert(getString(R.string.signing_in));
            this.SignIn();
        }
    }
    
    public void onSubmitScore(int score) {
        if (isSignedIn()) {
            switch (gameMode) {
            case 1:
                getGamesClient().submitScore(getString(R.string.leaderboard1),
                        score);
                break;
            case 2:
                getGamesClient().submitScore(getString(R.string.leaderboard2),
                        score);
                break;
            case 3:
                getGamesClient().submitScore(getString(R.string.leaderboard3),
                        score);
                break;
            }
        } else {
            showAlert(getString(R.string.signing_in));
            this.SignIn();
        }
    }
    
    boolean verifyPlaceholderIdsReplaced() {
        final boolean CHECK_PKGNAME = true; // set to false to disable check
                                            // (not recommended!)
    
        // Did the developer forget to change the package name?
        if (CHECK_PKGNAME && getPackageName().startsWith("com.google.example.")) {
            Log.e(TAG,
                    "*** Sample setup problem: "
                            + "package name cannot be com.google.example.*. Use your own "
                            + "package name.");
            return false;
        }
    
        // Did the developer forget to replace a placeholder ID?
        // int res_ids[] = new int[] {
        // R.string.app_id
        // };
        // for (int i : res_ids) {
        // if (getString(i).equalsIgnoreCase("ReplaceMe")) {
        // Log.e(TAG, "*** Sample setup problem: You must replace all " +
        // "placeholder IDs in the ids.xml file by your project's IDs.");
        // return false;
        // }
        // }
        return true;
    }
    
    public void SignIn() {
        if (!verifyPlaceholderIdsReplaced()) {
            showAlert("Sample not set up correctly. See README.");
            return;
        }
    
        // start the sign-in flow
        beginUserInitiatedSignIn();
    }
    
    @Override
    public void onSignInFailed() {
        System.out.println("SignIn Failed!");
        // Intent mainIntent = new Intent(FirstActivity.this,
        // FlappyBirdActivity.class);
        // FirstActivity.this.startActivity(mainIntent);
        // FirstActivity.this.finish();
    }
    
    @Override
    public void onSignInSucceeded() {
        System.out.println("SignIn Successed!");
        onShowLeaderboard();
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 2023-04-03
      • 2014-12-19
      • 1970-01-01
      • 2014-03-26
      • 2018-02-07
      • 2016-08-09
      • 2013-05-12
      • 2018-01-05
      相关资源
      最近更新 更多