Google Play游戏服务,显示排行榜无效

时间:2015-07-13 00:00:34

标签: android google-play-services google-play-games

我正在尝试在我的应用中实施Google Play游戏服务。登录工作完美,但是当我按下show showboard按钮时没有任何反应。我必须提到我的应用程序没有发布我只是用我的测试帐户测试Google Play游戏功能(也许这就是为什么它不起作用,我不知道)。 这是我的项目架构:

enter image description here

这是我的gradle设置:

dependencies {
compile project(':BaseGameUtils')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
...
//google play game services
compile 'com.google.android.gms:play-services:7.5.0'

}

此活动包括Google登录+排行榜按钮

public class StartActivity extends BaseGameActivity implements View.OnClickListener {
private ImageView mPlay;

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

    mPlay = (ImageView)findViewById(R.id.startGameView);
    mPlay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //play animations
            YoYo.with(Techniques.Pulse)
                    .duration(200)
                    .playOn(findViewById(R.id.startGameView));
            Intent intent = new Intent(StartActivity.this, MainActivity.class);
            startActivity(intent);
        }
    });
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_start, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onSignInFailed() {
    findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
    findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}

@Override
public void onSignInSucceeded() {
    findViewById(R.id.sign_in_button).setVisibility(View.GONE);
    findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}

@Override
public void onClick(View view) {
    if (view.getId() == R.id.sign_in_button) {
        beginUserInitiatedSignIn();
    }
    else if (view.getId() == R.id.sign_out_button) {
        signOut();
        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        findViewById(R.id.sign_out_button).setVisibility(View.GONE);
    }else if (view.getId() == R.id.show_achievements){
        startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), 1);
    }else if(view.getId() == R.id.show_leaderboard){
        startActivityForResult(Games.Leaderboards.getLeaderboardIntent(
                        getApiClient(), getString(R.string.number_of_solved_math_problems_leaderboard)),2);
    }
}

这是XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/backrepeat"
            android:paddingBottom="@dimen/activity_vertical_margin"
            tools:context="koemdzhiev.com.mathmadness.StartActivity">


<!-- sign-in button -->
<com.google.android.gms.common.SignInButton
    android:id="@+id/sign_in_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/startGameView"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="43dp"/>

<!-- sign-out button -->
<Button
    android:id="@+id/sign_out_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sign Out"
    android:visibility="gone" />

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:id="@+id/startGameView"
    android:src="@drawable/play"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"/>

<LinearLayout
    android:layout_marginTop="100dp"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <!-- show achievements -->
    <Button
        android:id="@+id/show_achievements"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Achievements"
        android:layout_alignBaseline="@+id/show_leaderboard"
        android:layout_alignBottom="@+id/show_leaderboard"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"/>

    <!-- show leaderboards -->
    <Button
        android:id="@+id/show_leaderboard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Leaderboard"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"/>
</LinearLayout>

0 个答案:

没有答案