当玩家从游戏屏幕点击此按钮时,我想以编程方式直接为我的游戏启动Google Play游戏页:
我想要启动的页面示例如下:
https://drive.google.com/file/d/0B8Xfkv7Sp0JzdzJiWWpFWG8zNHoydnMzWkwzZVJWZDJuUXZr/view?usp=sharing
有关这方面的任何想法/建议吗?
PS。我刚刚采取了随机的超棒游戏" BADLAND"举个例子 :)。希望没关系!
答案 0 :(得分:2)
已经有一段时间了,所以我不知道你是否已经找到了答案,但我今天基本上都在做同样的事情并且认为我会分享我的解决方案。我在网上找不到任何消息来源,最终反编译应用程序以查看它对启动它的意图的期望。
Intent intent = new Intent();
//Clear the activity so the back button returns to your app
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//Manually specify the package and activity name
intent.setComponent(new ComponentName("com.google.android.play.games", "com.google.android.gms.games.ui.destination.api.ApiActivity"));
//Not really needed as default happens if you don't specify it.
intent.addCategory(Intent.CATEGORY_DEFAULT);
//You must specify the current players user. It ensures that Google Play Games is logged in as the same person.
intent.putExtra("com.google.android.gms.games.ACCOUNT_KEY", Games.Players.getCurrentPlayerId(googleApiClient));
intent.putExtra("com.google.android.gms.games.SCREEN", 1050); //"Magic" number from the source code for the about page
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient));
startActivity(intent);
请注意,页面本身使用的是硬编码。我测试了几个版本的Google Play游戏并且它们有效,但我仍未找到定义值的位置。您可能还希望为未安装Google Play游戏等情况添加一些错误处理。
答案 1 :(得分:1)
现在已弃用接受的答案。请执行以下操作:
Create these methods in AccountUtil.class (Or whatever you may call it):
fun getGamesAccount(): GoogleSignInAccount? {
return GoogleSignIn.getLastSignedInAccount(app)
}
fun getGamesPlayerInfo(): Task<Player>? {
val account = getGamesAccount()
return if (account != null) {
Games.getPlayersClient(app, account).currentPlayer
} else null
}
fun getPlayerProfileIntent(player: Player): Task<Intent>? {
val account = getGamesAccount()
return if (account != null) {
Games.getPlayersClient(app, account).getCompareProfileIntent(player)
}else null
}
然后,您可以像这样获得配置文件意图:
accountUtil.getGamesPlayerInfo()?.addOnSuccessListener { player ->
accountUtil.getPlayerProfileIntent(player)?.addOnSuccessListener {
startActivityForResult(it, PROFILE_REQUEST_CODE)
}
}
companion object {
const val PROFILE_REQUEST_CODE = 23423
}