Created
August 10, 2015 22:33
-
-
Save jamesmorrisstudios/fb3f009538b44931911b to your computer and use it in GitHub Desktop.
Example code for doing Google Play Games deep linking from an app using game services.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Build the basic intent. This is common to all linked pages | |
* This adds the current user's playerId. This is important. | |
*/ | |
public Intent buildDeepLinkIntent(GoogleApiClient googleApiClient) { | |
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)); | |
//I have not tested with this but there is an option to specify the minimum version | |
//intent.putExtra("com.google.android.gms.games.MIN_VERSION", ???); | |
return intent; | |
} | |
/** | |
* Fire the intent if Google Play Games is installed. | |
* Otherwise handle the error | |
*/ | |
public boolean startGooglePlayGames(Intent intent) { | |
//This assumes it is running in a fragment. Adjust getActivity() as needed. | |
PackageManager packageManager = getActivity().getPackageManager(); | |
List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | |
boolean isIntentSafe = activities.size() > 0; | |
if(isIntentSafe) { | |
startActivity(intent); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/** | |
* Launches the about screen for your game | |
*/ | |
public void intentAbout(Intent intent, GoogleApiClient googleApiClient) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1050); | |
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient)); | |
} | |
/** | |
* Launches the achievements page | |
*/ | |
public void intentAchievements(Intent intent, GoogleApiClient googleApiClient) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1051); | |
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient)); | |
} | |
/** | |
* Launches the leaderboards page | |
*/ | |
public void intentLeaderboards(Intent intent, GoogleApiClient googleApiClient) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1052); | |
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient)); | |
} | |
/** | |
* Launches to a specific leaderboard. You must specify the leaderboardId | |
*/ | |
public void intentLeaderboardSpecific(Intent intent, GoogleApiClient googleApiClient, String leaderboardId) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1053); | |
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient)); | |
intent.putExtra("com.google.android.gms.games.LEADERBOARD_ID", leaderboardId); | |
} | |
/** | |
* Launches the list of players (in your circles) with this game. | |
*/ | |
public void intentPlayers(Intent intent, GoogleApiClient googleApiClient) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1054); | |
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient)); | |
} | |
/** | |
* Launches the quests available for this game | |
*/ | |
public void intentQuests(Intent intent, GoogleApiClient googleApiClient) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1055); | |
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient)); | |
} | |
/** | |
* Shows the current players profile DEPRECIATED) | |
*/ | |
public void intentProfileDepreciated(Intent intent) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1100); | |
} | |
/** | |
* Shows the current players profile | |
*/ | |
public void intentProfile(Intent intent) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1101); | |
} | |
/** | |
* Shows the compare profiles page. You must pass a full Player object for the second player. | |
* Make sure you use .freeze() on it so you can release your buffers. | |
*/ | |
public void intentProfileCompare(Intent intent, com.google.android.gms.games.Player player) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1102); | |
intent.putExtra("com.google.android.gms.games.OTHER_PLAYER", player); | |
} | |
/** | |
* Show the inbox (matches) list. | |
*/ | |
public void intentInbox(Intent intent) { | |
intent.putExtra("com.google.android.gms.games.SCREEN", 1200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment