private PendingResult writeSnapshot(Snapshot snapshot,
byte[] data, Bitmap coverImage, String desc) {
You can call open with a filename that does not exist to create a new snapshot. This snippet uses .await() on the result from open, so you'll need to call it from an AsyncTask or some other non-UI thread. (see https://developers.google.com/games/services/android/savedgames for more details):
private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(String newSnapshotFilename,
byte[] data, Bitmap coverImage, String desc) {
Snapshots.OpenSnapshotResult result =
Games.Snapshots.open(mGoogleApiClient, newSnapshotFilename, true).await();
// Check the result of the open operation
if (result.getStatus().isSuccess()) {
Snapshot snapshot = result.getSnapshot();
snapshot.getSnapshotContents().writeBytes(data);
// Create the change operation
SnapshotMetadataChange metadataChange = new
SnapshotMetadataChange.Builder()
.setCoverImage(coverImage)
.setDescription(desc)
.build();
// Commit the operation
return Games.Snapshots.commitAndClose(mGoogleApiClient, snapshot, metadataChange);
}
return null;
}