gpt4 book ai didi

google-play-games - 获取对快照的引用。 Google Play 游戏服务保存的游戏

转载 作者:行者123 更新时间:2023-12-02 00:59:48 24 4
gpt4 key购买 nike

       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

文档说必须在调用 writeSnaphot 之前获取对快照的引用。由于快照是一个接口(interface),因此无法使用 new 创建它。

如何获取对快照的引用?

谢谢!

附言我看到有一种方法可以通过按名称打开现有的已保存游戏来获取引用,但是我想获得的引用是针对新快照的,目前没有现有快照,因此使用加载功能可能无法成功编写新快照。

最佳答案

您可以使用不存在的文件名调用 open 来创建新的快照。此代码段对打开的结果使用 .await(),因此您需要从 AsyncTask 或其他一些非 UI 线程调用它。 (有关详细信息,请参阅 https://developers.google.com/games/services/android/savedgames):

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;
}

关于google-play-games - 获取对快照的引用。 Google Play 游戏服务保存的游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29969656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com