Getting a link to a snapshot. Google Play Games Services Saved Games

private PendingResult<Snapshots.CommitSnapshotResult> writeSnapshot(Snapshot snapshot, byte[] data, Bitmap coverImage, String desc) { // Set the data payload for the snapshot 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); } 

https://developers.google.com/games/services/android/savedgames

The docs say that a snapshot link must be obtained before calling writeSnaphot. Since the snapshot is an interface, it cannot be created using the new one.

How to get a link to a snapshot?

Thanks!

PS I see that there is a way to get a link by opening an existing saved game by name, but the link that I would like to get is for a new snapshot in which there are currently no existing snapshots, so using the download function is probably not will be able to write a new picture.

+2
source share
1 answer

You can call open with a file name that is not there to create a new snapshot. This snippet uses .await () as a result from open, so you will need to call it from AsyncTask or another thread other than the UI. (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; } 
+7
source

Source: https://habr.com/ru/post/988664/


All Articles