Implement the Home Screen Shortcut API to help players quickly return to your game. This API displays an in-game dialog that lets players create the following shortcuts:
The Home Screen Shortcut API prompts the player to add a shortcut to your game on their Android home screen. The player can either add the shortcut automatically or drag the icon to their preferred location.
The Home Screen Shortcut API prompts the player to pin your game to their Play shortcuts. Your game will also be added to the player's list of pinned games and their game list.
The Home Screen Shortcut API consists of the following methods of the GameFeaturesLibrary
class.
Indicates whether your game can prompt the user to create a Home Screen shortcut.
public static void canCreateShortcut( Context context, JSONObject parameters, DaemonRequest.Callback callback)
Prompts the user to create a Home Screen shortcut for your game. This method can be called only once per session.
public static void createShortcut( Context context, JSONObject parameters, DaemonRequest.Callback callback)
The following example demonstrates how to use the GameFeaturesLibrary.canCreateShortcut
method to determine whether your game can create a Home Screen shortcut.
GameFeaturesLibrary.canCreateShortcut(
Context context,
null,
new DaemonRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (response.getError() != null) {/*Handle the error.*/}
else {
try {
JSONObject data = response.getJSONObject();
boolean canCreateShortcut = data.getBoolean("canCreateShortcut");
if (canCreateShortcut) {
GameFeaturesLibrary.createShortcut(
Context context,
null,
DaemonRequest.Callback callback)
}
} catch (JSONException e) {/*Handle the exception.*/}
}
}
}
)