Search code examples
androidandroid-intentandroid-activitygoogle-play-servicesgoogle-play-games

How do I programmatically launch the "Google Play Games Profile" Game Page


I want to directly launch the Google Play Game Page for my game programmatically when the player hits this button from the game screen:

Google Play Game Controller Icon

An example of the page I want to launch to is: Google Play Game Page

https://drive.google.com/file/d/0B8Xfkv7Sp0JzdzJiWWpFWG8zNHoydnMzWkwzZVJWZDJuUXZr/view?usp=sharing

Any thoughts/suggestions on doing this?

PS. I've just taken a random awesome game "BADLAND" as an example :). Hope that's okay!


Solution

  • It has been a while so I don't know if you found the answer already but I have been working on essentially the same thing today and figured I would share my solution. I found no sources on this online and ended up decompiling the app to look at what it expects for the intents to launch it.

    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);
    

    Note that the page itself uses a hard coded number. I tested over several versions of Google Play Games and they worked but I still haven't found where the value is defined. You may also want to add in some error handling for cases such as Google Play Games not being installed.

    Details on more pages such as profile compare

    Github Gist of all pages