当我在createMatch()
上调用TurnBasedMultiplayerClient
时,它返回的任务是false(task.isSuccessful)
,而得到的异常是com.google.android.gms.common.api.ApiException: 26502: CLIENT_RECONNECT_REQUIRED
。
该文档说GoogleApiClient处于不一致状态,但是如何重新连接呢?我没有GoogleAPiClient
对象,所以不能只调用GoogleAPiClient.reconnect()
。
我正在使用默认的ui来选择玩家:
private fun onStartMatchClicked() {
val allowAutoMatch = true
mTurnBasedMultiplayerClient = Games.getTurnBasedMultiplayerClient(this@MultiplayerActivity, clientAccount!!)
mTurnBasedMultiplayerClient!!.getSelectOpponentsIntent(1, 1, allowAutoMatch)
.addOnSuccessListener { intent -> startActivityForResult(intent, RC_SELECT_PLAYERS) }
}
这是onActivityResult方法:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SELECT_PLAYERS) {
if (resultCode != Activity.RESULT_OK) {
finish()
return
}
val invitees = data!!.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS)
// Get automatch criteria
var autoMatchCriteria: Bundle? = null
val minAutoPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0)
val maxAutoPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0)
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoPlayers,
maxAutoPlayers, 0)
val tbmc = TurnBasedMatchConfig.builder()
.addInvitedPlayers(invitees)
.setAutoMatchCriteria(autoMatchCriteria).build()
mTurnBasedMultiplayerClient!!.createMatch(tbmc).addOnCompleteListener { task ->
if (task.isSuccessful) { //this is where I get the exception
match = task.result
} else {
// There was an error. Show the error.
var status = CommonStatusCodes.DEVELOPER_ERROR
val exception = task.exception
if (exception is ApiException) {
val apiException = exception as ApiException?
status = apiException!!.statusCode
}
handleError(status, exception)
}
}
}
}