public interface

# Quests

com.google.android.gms.games.quest.Quests

## Class Overview

Entry point for Quest functionality.

## Summary

Nested Classes
interface | Quests.AcceptQuestResult | Result delivered when accepting a quest.
interface | Quests.ClaimMilestoneResult | Result delivered when claiming a milestone.
interface | Quests.LoadQuestsResult | Result delivered when quest data has been loaded.

Constants
String | EXTRA_QUEST | Intent extra used to pass a `Quest`.
int | SELECT_ACCEPTED | Constant used to add quests in the `STATE_ACCEPTED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_COMPLETED | Constant used to add quests in the `STATE_COMPLETED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_COMPLETED_UNCLAIMED | Constant used to add quests in the `STATE_COMPLETED` state that have at least one milestone in the `STATE_COMPLETED_NOT_CLAIMED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_ENDING_SOON | Constant used to add quests in the `STATE_ACCEPTED` state that have been marked as ending soon `isEndingSoon()` returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_EXPIRED | Constant used to add quests in the `STATE_EXPIRED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_FAILED | Constant used to add quests in the `STATE_FAILED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_OPEN | Constant used to add quests in the `STATE_OPEN` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SELECT_RECENTLY_FAILED | Constant used to add quests in the `STATE_FAILED` state with a `getLastUpdatedTimestamp()` no older than 7 days ago.
int | SELECT_UPCOMING | Constant used to add quests in the `STATE_UPCOMING` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.
int | SORT_ORDER_ENDING_SOON_FIRST | Sort requests with the quests ending soon first.
int | SORT_ORDER_RECENTLY_UPDATED_FIRST | Sort requests with the recently updated quests first.

Fields
public static final int[] | SELECT_ALL_QUESTS | Array of all the valid state selector constants.

Public Methods
abstract PendingResult<Quests.AcceptQuestResult> | accept(GoogleApiClient apiClient, String questId) Asynchronously accept the quest.
abstract PendingResult<Quests.ClaimMilestoneResult> | claim(GoogleApiClient apiClient, String questId, String milestoneId) Asynchronously claim the milestone.
abstract Intent | getQuestIntent(GoogleApiClient apiClient, String questId) Get an intent to view a single quest.
abstract Intent | getQuestsIntent(GoogleApiClient apiClient, int[] questSelectors) Get an intent to view a list of quests.
abstract PendingResult<Quests.LoadQuestsResult> | load(GoogleApiClient apiClient, int[] questSelectors, int sortOrder, boolean forceReload) Asynchronously load the quest data for the currently signed-in player and game into a single result, including only quests in the provided state array.
abstract PendingResult<Quests.LoadQuestsResult> | loadByIds(GoogleApiClient apiClient, boolean forceReload, String... questIds) Asynchronously load single quest data for the currently signed-in player and game.
abstract void | registerQuestUpdateListener(GoogleApiClient apiClient, QuestUpdateListener listener) Register a listener to listen for updates on `Quest` instances.
abstract void | showStateChangedPopup(GoogleApiClient apiClient, String questId) Display a popup based on the current state of the quest.
abstract void | unregisterQuestUpdateListener(GoogleApiClient apiClient) Unregisters this client's quest update listener, if any.

## Constants

#### public static final String EXTRA_QUEST

Intent extra used to pass a `Quest`.

##### See Also

- `getParcelableExtra(String)`

Constant Value: "quest"

#### public static final int SELECT_ACCEPTED

Constant used to add quests in the `STATE_ACCEPTED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.

Constant Value: 3 (0x00000003)

#### public static final int SELECT_COMPLETED

Constant used to add quests in the `STATE_COMPLETED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.

Constant Value: 4 (0x00000004)

#### public static final int SELECT_COMPLETED_UNCLAIMED

Constant used to add quests in the `STATE_COMPLETED` state that have at least one milestone in the `STATE_COMPLETED_NOT_CLAIMED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`. This is a subset of `SELECT_COMPLETED`, so the two criteria do not both need to be included to get all quests.

Constant Value: 101 (0x00000065)

#### public static final int SELECT_ENDING_SOON

Constant used to add quests in the `STATE_ACCEPTED` state that have been marked as ending soon `isEndingSoon()` returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`. This is a subset of `STATE_ACCEPTED`, so the two criteria do not both need to be included to get all quests.

Constant Value: 102 (0x00000066)

#### public static final int SELECT_EXPIRED

Constant used to add quests in the `STATE_EXPIRED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.

Constant Value: 5 (0x00000005)

#### public static final int SELECT_FAILED

Constant used to add quests in the `STATE_FAILED` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.

Constant Value: 6 (0x00000006)

#### public static final int SELECT_OPEN

Constant used to add quests in the `STATE_OPEN` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.

Constant Value: 2 (0x00000002)

#### public static final int SELECT_RECENTLY_FAILED

Constant used to add quests in the `STATE_FAILED` state with a `getLastUpdatedTimestamp()` no older than 7 days ago. In simple terms, it will include quests that the player attempted, but failed in the last 7 days. Use with the `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])` API endpoints. This is a subset of `STATE_FAILED`.

Constant Value: 103 (0x00000067)

#### public static final int SELECT_UPCOMING

Constant used to add quests in the `STATE_UPCOMING` state to the QuestBuffer returned by `load(GoogleApiClient, int[], int, boolean)` and `getQuestsIntent(GoogleApiClient, int[])`.

Constant Value: 1 (0x00000001)

#### public static final int SORT_ORDER_ENDING_SOON_FIRST

Sort requests with the quests ending soon first.

Constant Value: 1 (0x00000001)

#### public static final int SORT_ORDER_RECENTLY_UPDATED_FIRST

Sort requests with the recently updated quests first.

Constant Value: 0 (0x00000000)

## Fields

#### public static final int[] SELECT_ALL_QUESTS

Array of all the valid state selector constants.

## Public Methods

#### public abstract PendingResult<Quests.AcceptQuestResult> accept (GoogleApiClient apiClient, String questId)

Asynchronously accept the quest. This enters the player into an `STATE_OPEN` quest and will start tracking their progress towards the milestone goal.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
questId | The quest ID of the quest to accept.

##### Returns

- `PendingResult` to access the data when available.

#### public abstract PendingResult<Quests.ClaimMilestoneResult> claim (GoogleApiClient apiClient, String questId, String milestoneId)

Asynchronously claim the milestone. This method informs Google Play Games services that the player has completed the milestone on this device, and prevents the milestone from being claimed on another device by the same user. If the method call returns `STATUS_OK`, your app should reward the player based on the CompletionRewardData of the milestone.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
questId | The parent quest ID.
milestoneId | The ID of the milestone to claim.

##### Returns

- `PendingResult` to access the data when available.

#### public abstract Intent getQuestIntent (GoogleApiClient apiClient, String questId)

Get an intent to view a single quest. Note that this must be invoked using `startActivityForResult(Intent, int)` so that the identity of the calling package can be established.

The functionality of this activity is identical to `(GoogleApiClient, int[])`, the only difference being this activity displays a single quest rather than a list of quests. See `getQuestsIntent(GoogleApiClient, int[])` for usage details and behavior.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
questId | The ID of the quest to display.

##### Returns

- An `Intent` that can be started to view the quest.

#### public abstract Intent getQuestsIntent (GoogleApiClient apiClient, int[] questSelectors)

Get an intent to view a list of quests. Note that this must be invoked using `startActivityForResult(Intent, int)` so that the identity of the calling package can be established.

Quests that are open will contain an "Accept" button, while quests that are completed with unclaimed milestone rewards will have a "Claim Reward" button. Buttons will not be shown for quests in other states.

If the user clicks the "Accept" button on a quest, `accept(GoogleApiClient, String)` will be called. If the quest is successfully accepted, the activity will close with `RESULT_OK`, and the data intent will contain a parcelable object in `EXTRA_QUEST` indicating the accepted quest.

If the user clicks the "Claim Reward" button on a quest, the activity will close with `RESULT_OK`, and the data intent will contain a parcelable object in `EXTRA_QUEST` indicating the quest the user would like to claim a reward for. The caller is responsible for examining the state of this returned quest. If the quest state is `STATE_COMPLETED`, the caller should invoke `claim(GoogleApiClient, String, String)`. If the claim succeeds, the caller should then give the reward to the player.

If the user canceled, the result will be `RESULT_CANCELED`.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
questSelectors | Array of quest selectors to include in the list of quests. Valid values include: `SELECT_UPCOMING`, `SELECT_OPEN`, `SELECT_ACCEPTED`, `SELECT_ENDING_SOON`, `SELECT_COMPLETED`, `SELECT_COMPLETED_UNCLAIMED`, `SELECT_EXPIRED`, `SELECT_FAILED`, or `SELECT_RECENTLY_FAILED`. Use `SELECT_ALL_QUESTS` to view all quests.

##### Returns

- An `Intent` that can be started to view the list of quests.

#### public abstract PendingResult<Quests.LoadQuestsResult> load (GoogleApiClient apiClient, int[] questSelectors, int sortOrder, boolean forceReload)

Asynchronously load the quest data for the currently signed-in player and game into a single result, including only quests in the provided state array.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
questSelectors | An array of quest selectors to indicate which quest states to include. Valid values include: `SELECT_UPCOMING`, `SELECT_OPEN`, `SELECT_ACCEPTED`, `SELECT_ENDING_SOON`, `SELECT_COMPLETED`, `SELECT_COMPLETED_UNCLAIMED`, `SELECT_EXPIRED`, `SELECT_FAILED`, or `SELECT_RECENTLY_FAILED`. Use `SELECT_ALL_QUESTS` to view all quests.
sortOrder | The sort order to use for sorting the quests. Must be either `SORT_ORDER_ENDING_SOON_FIRST` or `SORT_ORDER_RECENTLY_UPDATED_FIRST`.
forceReload | If true, this call will clear any locally cached data and attempt to fetch the latest data from the server. This would commonly be used for something like a user-initiated refresh. Normally, this should be set to false to gain advantages of data caching.

##### Returns

- `PendingResult` to access the data when available.

#### public abstract PendingResult<Quests.LoadQuestsResult> loadByIds (GoogleApiClient apiClient, boolean forceReload, String... questIds)

Asynchronously load single quest data for the currently signed-in player and game.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
forceReload | If true, this call will clear any locally cached data and attempt to fetch the latest data from the server. This would commonly be used for something like a user-initiated refresh. Normally, this should be set to false to gain advantages of data caching.
questIds | The IDs of quests to retrieve.

##### Returns

- `PendingResult` to access the data when available.

#### public abstract void registerQuestUpdateListener (GoogleApiClient apiClient, QuestUpdateListener listener)

Register a listener to listen for updates on `Quest` instances.

Note that only one quest listener may be active at a time. Calling this method while another quest listener was previously registered will replace the original listener with the new one.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
listener | The listener that is called when the quest state changes.

#### public abstract void showStateChangedPopup (GoogleApiClient apiClient, String questId)

Display a popup based on the current state of the quest. Popups are only displayed for quests in `STATE_ACCEPTED`. If the quest is in any other state, no popup will be displayed. Call this from the onAccepted callbacks to show a popup for accepting a quest.

This method should generally be invoked at the point of quest acceptance (after the callback from `accept(GoogleApiClient, String)` returns).

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
questId | The ID of the quest to fetch assets from for the popup (name and images).

#### public abstract void unregisterQuestUpdateListener (GoogleApiClient apiClient)

Unregisters this client's quest update listener, if any.

Required API: `API`
Required Scopes: `SCOPE_GAMES`

##### Parameters

apiClient | The `GoogleApiClient` to service the call.