在Android上使用Drive Rest API实现Google Play游戏快照以保存游戏

时间:2019-02-11 14:19:21

标签: android google-drive-api google-play-games snapshot

我正在为现有游戏进行更新,我想将所有与Google Drive相关的资料迁移到Rest API。我想实现与Google Play游戏C ++ SDK V2.0相同的功能(将游戏状态保存到Google驱动器-快照)以支持向后兼容性。加载旧的保存游戏已经可以在新客户端上运行,但是反之则不行。

如果首先在新客户​​端上创建文件(快照),则旧客户端将无法识别该文件。当我尝试在旧客户端上下载文件时,它返回空文件,并且在同一操作中,它还将该空文件上传到驱动器上(现在appDataFolder中有两个同名文件)。如果下一步的新客户端将覆盖新的空文件,则旧客户端将成功下载该文件。

简短版本:更新现有文件有效,在新客户端上创建新文件无法加载到旧版本中。

我尝试尽可能地匹配新文件(play_games文件夹为父文件夹, mime类型设置为快照,描述相同,设备模型位于属性中),但我仍然缺少最后一个难题。

首先,我检查play_games文件夹是否存在,并在必要时创建它:

File meta = new File().setParents(Collections.singletonList("appDataFolder"))
    .setMimeType("application/vnd.google-apps.folder")
    .setName("play_games");

m_playGamesFolder = m_driveService.files()
    .create(meta)
    .execute();

这样创建新文件:

FileContent mediaContent = new FileContent("application/vnd.google-play-games.snapshot-initial", localContent);
Map<String, String> props = new HashMap<>();
props.put("deviceName", android.os.Build.MODEL);

File meta = new File()
        .setParents(Collections.singletonList(m_playGamesFolder.getId()))
        .setMimeType("application/vnd.google-play-games.snapshot-initial")
        .setName(fileName)
        .setDescription(m_description)
        .setProperties(props);

m_driveService.files().create(meta, mediaContent).execute();

更新是通过类似的方式完成的:

FileContent mediaContent = new FileContent("application/vnd.google-play-games.snapshot", localContent);
Map<String, String> props = new HashMap<>();
props.put("deviceName", android.os.Build.MODEL);

File meta = new File()
        .setName(fileName)
        .setDescription(m_description)
        .setProperties(props);

return m_driveService.files().update(cloudFile.getId(), meta, mediaContent).execute();

有人知道我在这里缺少什么吗?

0 个答案:

没有答案