如何以编程方式启动 "Google Play Games Profile" 游戏页面
How do I programmatically launch the "Google Play Games Profile" Game Page
我想当玩家从游戏屏幕点击此按钮时,以编程方式Google直接为我的游戏启动Google玩游戏页面:
我要启动的页面示例是:
https://drive.google.com/file/d/0B8Xfkv7Sp0JzdzJiWWpFWG8zNHoydnMzWkwzZVJWZDJuUXZr/view?usp=sharing
有没有thoughts/suggestions这样做的?
PS。我刚刚以一个随机的很棒的游戏 "BADLAND" 为例 :)。希望没关系!
已经有一段时间了,所以我不知道您是否已经找到答案,但我今天一直在做基本相同的事情,我想我会分享我的解决方案。我在网上找不到任何资源,最后反编译了该应用程序以查看它对启动它的意图的期望。
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 Games 的几个版本,它们都有效,但我仍然没有找到定义值的位置。您可能还想为 Google 未安装 Play 游戏等情况添加一些错误处理。
已接受的答案现已弃用。执行以下操作:
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
}
我想当玩家从游戏屏幕点击此按钮时,以编程方式Google直接为我的游戏启动Google玩游戏页面:
我要启动的页面示例是:
https://drive.google.com/file/d/0B8Xfkv7Sp0JzdzJiWWpFWG8zNHoydnMzWkwzZVJWZDJuUXZr/view?usp=sharing
有没有thoughts/suggestions这样做的?
PS。我刚刚以一个随机的很棒的游戏 "BADLAND" 为例 :)。希望没关系!
已经有一段时间了,所以我不知道您是否已经找到答案,但我今天一直在做基本相同的事情,我想我会分享我的解决方案。我在网上找不到任何资源,最后反编译了该应用程序以查看它对启动它的意图的期望。
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 Games 的几个版本,它们都有效,但我仍然没有找到定义值的位置。您可能还想为 Google 未安装 Play 游戏等情况添加一些错误处理。
已接受的答案现已弃用。执行以下操作:
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
}