Google Play服务排行榜不断突然出现

时间:2014-05-20 00:18:27

标签: android google-play-services

我一直试图控制何时弹出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();
}

1 个答案:

答案 0 :(得分:0)

解决了我一直试图控制何时弹出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();
}
相关问题