I'm trying to save and load snapshots with Play Games library but I'm stuck: I send my byte array and, I suppose, it is correctly saved in cloud because if I start the Intent given by
Games.Snapshots.getSelectSnapshotIntent(...)
I can see the saved snapshot.
On game restart I want to load the snapshot in background. Here the problem arises: the returned byte array is always empty and the saved snapshot is deleted from the cloud when I try to load it.
How could I save/load snapshots in the right way?
Snippet of the saving background method:
Snapshots.OpenSnapshotResult result =
Games.Snapshots.open(gameHelper.getApiClient(), "test_filename", true).await();
switch (result.getStatus().getStatusCode()) {
case GamesStatusCodes.STATUS_OK:
case GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT:
Snapshot snapshot = result.getSnapshot();
snapshot.getSnapshotContents().writeBytes(data);
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.setDescription("Modified data at: " + Calendar.getInstance().getTime())
.build();
Games.Snapshots
.commitAndClose(gameHelper.getApiClient(), snapshot, metadataChange)
.await();
return;
default:
throw new Exception();
}
Snippet of the loading background method:
Snapshots.OpenSnapshotResult result =
Games.Snapshots.open(gameHelper.getApiClient(), "test_filename", true).await();
switch (result.getStatus().getStatusCode()) {
case GamesStatusCodes.STATUS_OK:
case GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT:
Snapshot snapshot = result.getSnapshot();
byte[] data = snapshot.getSnapshotContents().readFully();
Games.Snapshots.discardAndClose(gameHelper.getApiClient(), snapshot);
return data;
default:
throw new Exception();
}
Note that I haven't any conflict or exception and that even with the SnapshotsCoordinator helper I didn't get it to work.
Play services version: 10.2.1