Obtaining a reference to a Snapshot. Google Play Games Services Saved Games

前端 未结 1 830
故里飘歌
故里飘歌 2021-01-22 16:46
       private PendingResult writeSnapshot(Snapshot snapshot,
                byte[] data, Bitmap coverImage, String desc) {

              


        
相关标签:
1条回答
  • 2021-01-22 17:31

    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;
    }
    
    0 讨论(0)
提交回复
热议问题