在我的活动中:公共类MenuActivity扩展活动实现ConnectionCallbacks,OnConnectionFailedListener
一旦我连接到Google+,我就会尝试调用排行榜。(仅供测试)
@Override
public void onConnected(Bundle bundle) {
try{
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,'myactual_leaderboard_id'), REQUEST_LEADERBOARD);
} catch (Exception e){
}
}
}startActivityForResult抛出一个NullPointerException。未请求所需的接口。
在我的Manifest.xml
meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />我已经将我的数字app_id作为字符串添加到了String.xml中。
游戏详情处于“准备测试”状态。
有人知道为什么会发生这种情况吗?
发布于 2014-04-15 13:31:46
是我的错。
我意识到我遗漏了mGoogleAPI中的一个声明。下面的两个语句都缺失。
.addApi(Games.API) .addScope(Games.SCOPE_GAMES)
我添加了它们之后问题就解决了。完整声明为:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API, null)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();https://stackoverflow.com/questions/23055352
复制相似问题