This interface is deprecated.
Use SnapshotsClient
instead
The Snapshots API allows you to store data representing the player's game progress on Google's servers. Your app can use this data to restore saved state from a previous gaming session and provide a visual indicator of progression to the player.
For more details, see the saved games developer guide.
Nested Class Summary
interface | Snapshots.CommitSnapshotResult | This interface is deprecated. SnapshotMetadata
is returned directly in the SnapshotsClient .
|
|
interface | Snapshots.DeleteSnapshotResult | This interface is deprecated.
snapshotId is returned directly in the SnapshotsClient .
|
|
interface | Snapshots.LoadSnapshotsResult | This interface is deprecated.
SnapshotMetadataBuffer is returned directly in the SnapshotsClient .
|
|
interface | Snapshots.OpenSnapshotResult | This interface is deprecated.
SnapshotsClient.DataOrConflict is returned instead in the SnapshotsClient .
|
Constant Summary
int | DISPLAY_LIMIT_NONE | Constant passed to
getSelectSnapshotIntent(GoogleApiClient, String, boolean, boolean, int)
indicating that the UI should not cap the number of displayed snapshots. |
String | EXTRA_SNAPSHOT_METADATA | Intent extra used to pass a SnapshotMetadata . |
String | EXTRA_SNAPSHOT_NEW | Intent extra used to indicate the user wants to create a new snapshot. |
int | RESOLUTION_POLICY_HIGHEST_PROGRESS | In the case of a conflict, the snapshot with the highest progress value will be used. |
int | RESOLUTION_POLICY_LAST_KNOWN_GOOD | In the case of a conflict, the last known good version of this snapshot will be used. |
int | RESOLUTION_POLICY_LONGEST_PLAYTIME | In the case of a conflict, the snapshot with the longest played time will be used. |
int | RESOLUTION_POLICY_MANUAL | In the case of a conflict, the result will be returned to the app for resolution. |
int | RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED | In the case of a conflict, the most recently modified version of this snapshot will be used. |
Public Method Summary
abstract PendingResult<Snapshots.CommitSnapshotResult> |
commitAndClose(GoogleApiClient
apiClient, Snapshot
snapshot,
SnapshotMetadataChange metadataChange)
Commit any modifications made to the snapshot.
|
abstract PendingResult<Snapshots.DeleteSnapshotResult> | |
abstract void |
discardAndClose(GoogleApiClient
apiClient, Snapshot
snapshot)
Discard the contents of the snapshot and close the contents.
|
abstract int |
getMaxCoverImageSize(GoogleApiClient
apiClient)
Gets the maximum data size per snapshot cover image in bytes.
|
abstract int | |
abstract Intent |
getSelectSnapshotIntent(GoogleApiClient
apiClient, String title,
boolean allowAddButton, boolean allowDelete, int maxSnapshots)
Returns an intent that will let the user select a snapshot.
|
abstract SnapshotMetadata |
getSnapshotFromBundle(Bundle extras)
|
abstract PendingResult<Snapshots.LoadSnapshotsResult> |
load(GoogleApiClient
apiClient, boolean forceReload)
Asynchronously load the snapshot data for the currently signed-in player.
|
abstract PendingResult<Snapshots.OpenSnapshotResult> |
open(GoogleApiClient
apiClient, SnapshotMetadata
metadata)
Open a snapshot with the given metadata (usually returned from
load(GoogleApiClient, boolean) .
|
abstract PendingResult<Snapshots.OpenSnapshotResult> |
open(GoogleApiClient
apiClient, String fileName,
boolean createIfNotFound)
Open a snapshot with the given name.
|
abstract PendingResult<Snapshots.OpenSnapshotResult> |
open(GoogleApiClient
apiClient, String fileName,
boolean createIfNotFound, int conflictPolicy)
Open a snapshot with the given name.
|
abstract PendingResult<Snapshots.OpenSnapshotResult> |
open(GoogleApiClient
apiClient, SnapshotMetadata
metadata, int conflictPolicy)
Open a snapshot with the given metadata (usually returned from
load(GoogleApiClient, boolean) .
|
abstract PendingResult<Snapshots.OpenSnapshotResult> |
resolveConflict(GoogleApiClient
apiClient, String conflictId,
String
snapshotId,
SnapshotMetadataChange metadataChange, SnapshotContents
snapshotContents)
Resolve a conflict using the provided data.
|
abstract PendingResult<Snapshots.OpenSnapshotResult> |
resolveConflict(GoogleApiClient
apiClient, String conflictId,
Snapshot
snapshot)
Resolve a conflict using the data from the provided snapshot.
|
Constants
public static final int DISPLAY_LIMIT_NONE
Constant passed to
getSelectSnapshotIntent(GoogleApiClient, String, boolean, boolean, int)
indicating that the UI should not cap the number of displayed snapshots.
public static final String EXTRA_SNAPSHOT_METADATA
Intent extra used to pass a SnapshotMetadata
.
public static final String EXTRA_SNAPSHOT_NEW
Intent extra used to indicate the user wants to create a new snapshot.
public static final int RESOLUTION_POLICY_HIGHEST_PROGRESS
In the case of a conflict, the snapshot with the highest progress value will be used. In the case of a tie, the last known good snapshot will be chosen instead.
This policy is a good choice if your game uses the progress value of the snapshot to
determine the best saved game. Note that you must use
SnapshotMetadataChange.Builder.setProgressValue(long)
when saving games for
this policy to be meaningful.
public static final int RESOLUTION_POLICY_LAST_KNOWN_GOOD
In the case of a conflict, the last known good version of this snapshot will be
used. This corresponds to the data that would be returned from
Snapshots.OpenSnapshotResult.getSnapshot()
in a custom merge.
This policy is a reasonable choice if your game requires stability from the snapshot data. This policy ensures that only writes which are not contested are seen by the player, which guarantees that all clients converge.
public static final int RESOLUTION_POLICY_LONGEST_PLAYTIME
In the case of a conflict, the snapshot with the longest played time will be used. In the case of a tie, the last known good snapshot will be chosen instead.
This policy is a good choice if the length of play time is a reasonable proxy for
the "best" save game. Note that you must use
SnapshotMetadataChange.Builder.setPlayedTimeMillis(long)
when saving games
for this policy to be meaningful.
public static final int RESOLUTION_POLICY_MANUAL
In the case of a conflict, the result will be returned to the app for resolution. No automatic resolution will be performed.
This policy ensures that no user changes to the state of the save game will ever be lost.
public static final int RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED
In the case of a conflict, the most recently modified version of this snapshot will
be used. This corresponds to the data that would be returned from
Snapshots.OpenSnapshotResult.getConflictingSnapshot()
in a custom merge.
This policy is a reasonable choice if your game can tolerate players on multiple devices clobbering their own changes. Because this policy blindly chooses the most recent data, it is possible that a player's changes may get lost.
Public Methods
public abstract PendingResult<Snapshots.CommitSnapshotResult> commitAndClose (GoogleApiClient apiClient, Snapshot snapshot, SnapshotMetadataChange metadataChange)
Commit any modifications made to the snapshot. This will cause the changes to be synced to the server in the background.
Calling this method with a snapshot that has already been committed or that was not
opened via
open(GoogleApiClient, SnapshotMetadata)
will throw an exception.
Note that the total size of the contents of snapshot
may not exceed the
size provided by
getMaxDataSize(GoogleApiClient)
.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
snapshot | The snapshot to commit the data for. |
metadataChange | The set of changes to apply to the metadata for the snapshot. Use
SnapshotMetadataChange.EMPTY_CHANGE to preserve the existing
metadata. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.DeleteSnapshotResult> delete (GoogleApiClient apiClient, SnapshotMetadata metadata)
Delete the specified snapshot. This will delete the data of the snapshot locally and on the server.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
metadata | The metadata of the snapshot to delete. |
Returns
PendingResult
to check the status of the operation.
public abstract void discardAndClose (GoogleApiClient apiClient, Snapshot snapshot)
Discard the contents of the snapshot and close the contents. This will discard all changes made to the file, and close the snapshot to future changes until it is re-opened. The file will not be modified on the server.
Calling this method with a snapshot that has already been committed or that was not
opened via
open(GoogleApiClient, SnapshotMetadata)
will throw an exception.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
snapshot | The snapshot to discard the data for. |
public abstract int getMaxCoverImageSize (GoogleApiClient apiClient)
Gets the maximum data size per snapshot cover image in bytes. Guaranteed to be at least 800 KB. May increase in the future.
If the service cannot be reached for some reason, this will return -1.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|
Returns
- The maximum data size per snapshot cover image in bytes.
public abstract int getMaxDataSize (GoogleApiClient apiClient)
Gets the maximum data size per snapshot in bytes. Guaranteed to be at least 3 MB. May increase in the future.
If the service cannot be reached for some reason, this will return -1.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|
Returns
- The maximum data size per snapshot in bytes.
public abstract Intent getSelectSnapshotIntent (GoogleApiClient apiClient, String title, boolean allowAddButton, boolean allowDelete, int maxSnapshots)
Returns an intent that will let the user select a snapshot. Note that this must be
invoked using
Activity.startActivityForResult(Intent, int)
so that the identity of the
calling package can be established.
If the user canceled without selecting a snapshot, the result will be Activity.RESULT_CANCELED
.
If the user selected a snapshot from the list, the result will be Activity.RESULT_OK
and the data intent will contain the selected Snapshot as a parcelable object in
EXTRA_SNAPSHOT_METADATA
. If the user pressed the add button, the result will
be Activity.RESULT_OK
and the data intent will contain a true
boolean value in
EXTRA_SNAPSHOT_NEW
.
Note that if you have modified an open snapshot, the changes will not appear in this
UI until you call
commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange)
on the
snapshot.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
title | The title to display in the action bar of the returned Activity. |
allowAddButton | Whether or not to display a "create new snapshot" option in the selection UI. |
allowDelete | Whether or not to provide a delete overflow menu option for each snapshot in the selection UI. |
maxSnapshots | The maximum number of snapshots to display in the UI. Use
DISPLAY_LIMIT_NONE to display all snapshots. |
Returns
- An
Intent
that can be started to view the select snapshot UI.
public abstract SnapshotMetadata getSnapshotFromBundle (Bundle extras)
public abstract PendingResult<Snapshots.LoadSnapshotsResult> load (GoogleApiClient apiClient, boolean forceReload)
Asynchronously load the snapshot data for the currently signed-in player.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
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. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.OpenSnapshotResult> open (GoogleApiClient apiClient, SnapshotMetadata metadata)
Open a snapshot with the given metadata (usually returned from
load(GoogleApiClient, boolean)
. To succeed, the snapshot must exist; i.e.
this call will fail if the snapshot was deleted between the load and open calls.
This will open the snapshot using
RESOLUTION_POLICY_MANUAL
as a conflict policy.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
metadata | The metadata of the existing snapshot to load. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.OpenSnapshotResult> open (GoogleApiClient apiClient, String fileName, boolean createIfNotFound)
Open a snapshot with the given name. If createIfNotFound
is set to
true
, the specified snapshot will be created if it does not already
exist.
This will open the snapshot using
RESOLUTION_POLICY_MANUAL
as a conflict policy.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
fileName | The name of the snapshot file to open. Must be between 1 and 100 non-URL-reserved characters (a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "~"). |
createIfNotFound | If true , the snapshot will be created if one cannot be found. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.OpenSnapshotResult> open (GoogleApiClient apiClient, String fileName, boolean createIfNotFound, int conflictPolicy)
Open a snapshot with the given name. If createIfNotFound
is set to
true
, the specified snapshot will be created if it does not already
exist.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
fileName | The name of the snapshot file to open. Must be between 1 and 100 non-URL-reserved characters (a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "~"). |
createIfNotFound | If true , the snapshot will be created if one cannot be found. |
conflictPolicy | The conflict resolution policy to use for this snapshot. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.OpenSnapshotResult> open (GoogleApiClient apiClient, SnapshotMetadata metadata, int conflictPolicy)
Open a snapshot with the given metadata (usually returned from
load(GoogleApiClient, boolean)
. To succeed, the snapshot must exist; i.e.
this call will fail if the snapshot was deleted between the load and open calls.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
metadata | The metadata of the existing snapshot to load. |
conflictPolicy | The conflict resolution policy to use for this snapshot. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.OpenSnapshotResult> resolveConflict (GoogleApiClient apiClient, String conflictId, String snapshotId, SnapshotMetadataChange metadataChange, SnapshotContents snapshotContents)
Resolve a conflict using the provided data. This will replace the data on the server with the specified metadata changes and contents. Note that it is possible for this operation to result in a conflict itself, in which case resolution should be repeated.
Values which are not included in the metadata change will be resolved to the version currently on the server.
Note that the total size of contents
may not exceed the size provided
by
getMaxDataSize(GoogleApiClient)
.
Calling this method with a snapshot that has already been committed or that was not
opened via
open(GoogleApiClient, SnapshotMetadata)
will throw an exception.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
conflictId | The ID of the conflict to resolve. Must come from
Snapshots.OpenSnapshotResult.getConflictId() . |
snapshotId | The ID of the snapshot to resolve the conflict for. |
metadataChange | The set of changes to apply to the metadata for the snapshot. |
snapshotContents | The SnapshotContents
to replace the snapshot data with. |
Returns
PendingResult
to access the data when available.
public abstract PendingResult<Snapshots.OpenSnapshotResult> resolveConflict (GoogleApiClient apiClient, String conflictId, Snapshot snapshot)
Resolve a conflict using the data from the provided snapshot. This will replace the data on the server with the specified snapshot. Note that it is possible for this operation to result in a conflict itself, in which case resolution should be repeated.
Note that the total size of the contents of snapshot
may not exceed the
size provided by
getMaxDataSize(GoogleApiClient)
.
Calling this method with a snapshot that has already been committed or that was not
opened via
open(GoogleApiClient, SnapshotMetadata)
will throw an exception.
Required API: Games.API
Required Scopes: Games.SCOPE_GAMES and Games.SCOPE_GAMES_SNAPSHOTS.
Parameters
apiClient | The GoogleApiClient
to service the call. |
---|---|
conflictId | The ID of the conflict to resolve. Must come from
Snapshots.OpenSnapshotResult.getConflictId() . |
snapshot | The snapshot to use to resolve the conflict. |
Returns
PendingResult
to access the data when available.