我无法在本机模拟器中连接到Google Play游戏服务,但是,相同的apk适用于Bluestacks。
到目前为止,应用程序通过Games.Achievements.getAchievementsIntent请求用户的成就列表。这些成就已在Bluestacks中成功显示,但是,本机模拟器屏幕仍为空白。
说实话,当Bluestacks显示用户的成就时(如下所示),我没有实现任何表示逻辑,这是一个惊喜。
我正在使用Google Play服务9.6.1构建依赖关系:
compile 'com.google.android.gms:play-services-games:9.6.1'
模拟器正在使用API 24 + Google API运行系统映像
我正在使用自动管理的GoogleApiClient实例尝试连接,但后来失败了。我尝试了很多修复无济于事。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this,
this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.build();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("onActivityResult", "resultCode = " + resultCode);
if (resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
mGoogleApiClient.connect();
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.d("onConnected", "onConnected");
startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient), MY_REQ_CODE);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d("onConnectionFailed", "onConnectionFailed");
mGoogleApiClient.connect();
}
Android监视器中的结果:
Connected to process 7907 on device Nexus_5X_API_24_GApps [emulator-5554]
W/System: ClassLoader referenced unknown path: /data/app/goc.dma.cprach.gameofchairs-1/lib/x86
W/PopupManager: You have not specified a View to use as content view for popups. Falling back to the Activity content view. Note that this may not work as expected in multi-screen environments
D/AutoManageHelper: starting AutoManage for client 0 false false
D/onStart: onStart
D/AutoManageHelper: onStart true {0=com.google.android.gms.internal.zzqa$zza@e9fa141}
[ 10-20 03:00:11.990 1490: 1511 D/ ]
HostConnection::get() New Host Connection established 0x8c3f9680, tid 1511
W/gralloc_ranchu: Gralloc pipe failed
[ 10-20 03:00:12.089 7907: 7907 D/ ]
HostConnection::get() New Host Connection established 0xa438dac0, tid 7907
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/onConnectionFailed: onConnectionFailed
D/AutoManageHelper: beginFailureResolution for ConnectionResult{statusCode=RESOLUTION_REQUIRED, resolution=PendingIntent{20c0bc3: android.os.BinderProxy@6889c40}, message=null}
D/onActivityResult: resultCode = 0
答案 0 :(得分:0)
我不确定这是否会有所帮助,但我在错误日志中注意到它说:
"You have not specified a View to use as content view for popups."
选中SO thread,建议:
使用setViewForPopUps方法
Games.setViewForPopups(getApiClient(), getWindow().getDecorView().findViewById(android.R.id.content));
另一种方法是:
在mGoogleApiClient对象中定义setViewForPopups。
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
.setViewForPopups(findViewById(android.R.id.content))
.build();
看看你的代码,似乎你还没有添加这个。以下是对setViewForPopups method的补充阅读。