Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌排行榜提交分数不';行不通_Android_Leaderboard - Fatal编程技术网

Android 谷歌排行榜提交分数不';行不通

Android 谷歌排行榜提交分数不';行不通,android,leaderboard,Android,Leaderboard,你能解释一下为什么command游戏、排行榜、submitScore(mgoogleapClient、排行榜id、分数)不起作用吗?当我上传Alpha测试中的签名apk时:登录有效,加载排行榜也有效,但排行榜上没有显示任何分数 这是我的主要活动,包括所有谷歌服务 imports... public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks

你能解释一下为什么command
游戏、排行榜、submitScore(mgoogleapClient、排行榜id、分数)
不起作用吗?当我上传Alpha测试中的签名apk时:登录有效,加载排行榜也有效,但排行榜上没有显示任何分数

这是我的主要活动,包括所有谷歌服务

imports...

public class MainActivity extends AppCompatActivity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        View.OnClickListener {

    FragmentManager mFragmentManager;
    FragmentTransaction mFragmentTransaction;
    FrameLayout fragmentView;

    int actualFragment;

    public boolean accountConnected;

    com.google.android.gms.common.SignInButton signIn;
    Button signOut;

    private GoogleApiClient mGoogleApiClient;

    private static int RC_SIGN_IN = 9001;

    private boolean mResolvingConnectionFailure = false;
    private boolean mAutoStartSignInFlow = true;
    private boolean mSignInClicked = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);

        accountConnected = prefs.getBoolean("accountIsConnected", false);
        // Create the Google Api Client with access to the Play Games services
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES)
                .build();

        fragmentView = (FrameLayout) findViewById(R.id.fragmentView);

        mFragmentManager = getSupportFragmentManager();
        mFragmentTransaction = mFragmentManager.beginTransaction();
        mFragmentTransaction.replace(R.id.fragmentView, new MenuFragment()).commit();
        actualFragment = 0;

        signIn = (com.google.android.gms.common.SignInButton) findViewById(R.id.sign_in_button);
        signIn.setOnClickListener(this);
        signOut = (Button) findViewById(R.id.sign_out_button);
        signOut.setOnClickListener(this);
    }

    public void loadLeaderboard() {
        if(accountConnected) {
            Intent leaderboard = new Intent(Games.Leaderboards.getAllLeaderboardsIntent(mGoogleApiClient));
            startActivityForResult(leaderboard, 2);
        }
    }

    public void loadClassicHighscore() {
        if (accountConnected) {
            Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, getString(R.string.classic_leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
                @Override
                public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
                    if (isScoreResultValid(scoreResult)) {
                        SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);
                        prefs.edit().putInt("classic_highscore", (int) scoreResult.getScore().getRawScore()).apply();
                    }
                }
            });
        }
    }

    public void loadZenHighscore() {
        if (mGoogleApiClient.isConnected()) {
            Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, getString(R.string.zen_leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
                @Override
                public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
                    if (isScoreResultValid(scoreResult)) {
                        SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);
                        prefs.edit().putInt("zen_highscore", (int) scoreResult.getScore().getRawScore()).apply();
                    }
                }
            });
        }
    }

    private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult) {
        return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null;
    }

    public void submitClassicHighscore(long score) {
        if(mGoogleApiClient.isConnected()) {
            Games.Leaderboards.submitScore(mGoogleApiClient, String.valueOf(R.string.classic_leaderboard_id), score);
            Games.Leaderboards.submitScoreImmediate(mGoogleApiClient, String.valueOf(R.string.classic_leaderboard_id), score);
        } else {
            Toast.makeText(this, "unable to submit highscore", Toast.LENGTH_SHORT).show();
        }
    }

    public void submitZenHighscore(long score) {
        if(mGoogleApiClient.isConnected()) {
            Games.Leaderboards.submitScore(mGoogleApiClient, String.valueOf(R.string.zen_leaderboard_id), score);
        } else {
            Toast.makeText(this, "unable to submit highscore", Toast.LENGTH_SHORT).show();
        }
    }

    // Call when the sign-in button is clicked
    private void signInClicked() {
        mSignInClicked = true;
        mGoogleApiClient.connect();
    }

    // Call when the sign-out button is clicked
    private void signOutclicked() {
        mSignInClicked = false;
        Games.signOut(mGoogleApiClient);
    }

    @Override
    protected void onStart() {
        super.onStart();
        SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);
        if (prefs.getBoolean("accountIsConnected", false) == true) {
            mGoogleApiClient.connect();
            accountConnected = true;
            prefs.edit().putBoolean("accountIsConnected", accountConnected).apply();
        } else {
            accountConnected = false;
            prefs.edit().putBoolean("accountIsConnected", accountConnected).apply();
        }
    }

    @Override
    protected void onStop() {
        SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);
        prefs.edit().putBoolean("accountIsConnected", accountConnected).apply();
        super.onStop();
        mGoogleApiClient.disconnect();
    }

    @Override
    public void onConnected(Bundle bundle) {
        // show sign-out button, hide the sign-in button
        signIn.setVisibility(View.GONE);
        signOut.setVisibility(View.VISIBLE);

        accountConnected = true;
        loadClassicHighscore();
        loadZenHighscore();
        SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);
        submitClassicHighscore(prefs.getInt("classic_highscore", 0));
        submitZenHighscore(prefs.getInt("zen_highscore", 0));
        prefs.edit().putBoolean("accountIsConnected", accountConnected).apply();

        // (your code here: update UI, enable functionality that depends on sign in, etc)
    }

    @Override
    public void onConnectionSuspended(int i) {
        // Attempt to reconnect
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        if (mResolvingConnectionFailure) {
            // Already resolving
            return;
        }

        // If the sign in button was clicked or if auto sign-in is enabled,
        // launch the sign-in flow
        if (mSignInClicked || mAutoStartSignInFlow) {
            mAutoStartSignInFlow = false;
            mSignInClicked = false;
            mResolvingConnectionFailure = true;

            // Attempt to resolve the connection failure using BaseGameUtils.
            // The R.string.signin_other_error value should reference a generic
            // error string in your strings.xml file, such as "There was
            // an issue with sign in, please try again later."
            if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult, RC_SIGN_IN, "Something went wrong!")) {
                mResolvingConnectionFailure = false;
            }
        }

        // Put code here to display the sign-in button
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == RC_SIGN_IN) {
            mSignInClicked = false;
            mResolvingConnectionFailure = false;
            if (resultCode == RESULT_OK) {
                mGoogleApiClient.connect();
            } else {
                accountConnected = false;
                SharedPreferences prefs = getSharedPreferences("com.thematus.twinz", MODE_PRIVATE);
                prefs.edit().putBoolean("accountIsConnected", accountConnected).apply();
                BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_failure);
            }
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.sign_in_button) {
            mSignInClicked = true;
            mGoogleApiClient.connect();
        }
        else if (v.getId() == R.id.sign_out_button) {
            // sign out.
            mSignInClicked = false;
            Games.signOut(mGoogleApiClient);

            // show sign-in button, hide the sign-out button
            signIn.setVisibility(View.VISIBLE);
            signOut.setVisibility(View.GONE);
        }
    }
}
导入。。。
公共类MainActivity扩展了AppCompatActivity实现
GoogleAppClient.ConnectionCallbacks,
GoogleAppClient.OnConnectionFailedListener,
View.OnClickListener{
碎片管理器;
零碎交易;
框架布局碎片视图;
int实际碎片;
公共网络连接;
com.google.android.gms.common.signIn按钮signIn;
按钮签出;
私人GoogleapClient MGoogleapClient;
专用静态输入RC_SIGN_IN=9001;
私有布尔值mResolvingConnectionFailure=false;
私有布尔mAutoStartSignInFlow=true;
私有布尔值mSignInClicked=false;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedReferences prefs=getSharedReferences(“com.thematus.twinz”,MODE_PRIVATE);
accountConnected=prefs.getBoolean(“accountIsConnected”,false);
//创建可访问Play Games服务的Google Api客户端
mgoogleapclient=新的Googleapclient.Builder(此)
.addConnectionCallbacks(此)
.addOnConnectionFailedListener(此)
.addApi(Games.API).addScope(Games.SCOPE\u Games)
.build();
fragmentView=(FrameLayout)findViewById(R.id.fragmentView);
MFFragmentManager=getSupportFragmentManager();
MFFragmentTransaction=MFFragmentManager.beginTransaction();
替换(R.id.fragmentView,新菜单片段()).commit();
实际碎片=0;
signIn=(com.google.android.gms.common.SignInButton)findViewById(R.id.sign_in_按钮);
signIn.setOnClickListener(此);
signOut=(按钮)findviewbyd(R.id.sign\u out\u按钮);
setOnClickListener(这个);
}
公共无效加载排行榜(){
如果(已连接帐户){
意向排行榜=新意向(Games.Leadboards.GetAllLeadboardsInt(MGooGleapicClient));
startActivityForResult(排行榜2);
}
}
公共void loadClassicHighscore(){
如果(已连接帐户){
游戏。排行榜。LoadCurrentPlayerLeadboardScore(mgoogleapClient,getString(R.string.classic\u Leadboard\u id),LeadboardVariant.TIME\u SPAN\u ALL\u TIME,LeadboardVariant.COLLECTION\u PUBLIC)。setResultCallback(新结果Callback(){
@凌驾
公开作废onResult(最终排行榜。LoadPlayerCoreResult得分结果){
if(isScoreResultValid(scoreResult)){
SharedReferences prefs=getSharedReferences(“com.thematus.twinz”,MODE_PRIVATE);
prefs.edit().putin(“classic_highscore”,(int)scoresult.getScore().getRawScore()).apply();
}
}
});
}
}
公共无效加载ZenHighScore(){
if(mgoogleapClient.isConnected()){
游戏。排行榜。LoadCurrentPlayerLeadboardScore(mgoogleapClient,getString(R.string.zen\u Leadboard\u id),LeadboardVariant.TIME\u SPAN\u ALL\u TIME,LeadboardVariant.COLLECTION\u PUBLIC)。setResultCallback(新结果Callback(){
@凌驾
公开作废onResult(最终排行榜。LoadPlayerCoreResult得分结果){
if(isScoreResultValid(scoreResult)){
SharedReferences prefs=getSharedReferences(“com.thematus.twinz”,MODE_PRIVATE);
prefs.edit().putInt(“zen_highscore”,(int)scoresult.getScore().getRawScore()).apply();
}
}
});
}
}
私有布尔值isScoreResultValid(最终排行榜。LoadPlayers CoreResult scoreResult){
返回scoreResult!=null&&GamesStatusCodes.STATUS\u OK==scoreResult.getStatus().getStatusCode()&&scoreResult.getScore()!=null;
}
公共无效提交分类分数(长分数){
if(mgoogleapClient.isConnected()){
游戏。排行榜。提交核心(mgoogleapclient,String.valueOf(R.String.classic_排行榜_id),分数);
游戏。排行榜。提交即时(mgoogleapclient,String.valueOf(R.String.classic_排行榜_id),分数);
}否则{
Toast.makeText(这是“无法提交高分”,Toast.LENGTH_SHORT.show();
}
}
公共无效提交人高分数(长分数){
if(mgoogleapClient.isConnected()){
游戏。排行榜。提交核心(mGoogleApiClient,String.valueOf(R.String.zen_排行榜_id),分数);
}否则{
Toast.makeText(这是“无法提交高分”,Toast.LENGTH_SHORT.show();
}
}
//单击“登录”按钮时调用
私人无效签名已签名(){
mSignInClicked=true;
mGoogleApiClient.connect();
}
//单击注销按钮时调用
私有void signOutclicked(){
mSignInClicked=false;
游戏签到(mGoogleApiClient);
}
@凌驾
受保护的void onStart(){
super.onStart();
SharedReferences prefs=getSharedReferences(“com.thematus.twinz”,MODE_PRIVATE);
if(prefs.getBoolean(“accountIsConnected”,false)=true){
mGoogleApiClient.connect();
accountConnected=true;
prefs.edit().putBoolean(“accountIsConnected”,accountConnected).apply();
}否则{
accountConnected=false;
prefs.edi