android - 从 SqliteDatabase 创建字节数组以使用 Google Saved Games 保存它?

标签 android android-sqlite google-play-games

我有一个游戏,我使用几个表来存储玩家的进度。这是一个相当长的游戏,所以我时不时会收到关于为什么我没有云保存选项的合法用户反馈?

因此,我确实使用 Google Play 游戏登录来取得成就,我想我可以简单地实现 Google Saved Games也很简单。

正如我所见,它使用一个简单的 byte[] 数组来从云端保存和加载游戏进度。(实际上是 Google Drive。)

我的问题是,如何创建一个 byte[] 数组来保存玩家已保存游戏实例的完整数据库?

我正在使用Sqlite数据库,例如:

private static DatabaseHelper mInstance = null;


private DatabaseHelper(Context context) {
    super(context, "duels_rpg_db", null, 123);
  

    this.ctx = context;

 
    getWritableDatabase();
}


public static DatabaseHelper getInstance(Context ctx) {

   
    if (mInstance == null) {
        mInstance = new DatabaseHelper(ctx.getApplicationContext());
    }
    return mInstance;
}

等等,没什么特别的。

提前致谢,

最佳答案

如果你是using C it would be easy to serialize the entire database ,但在 Android 中我认为你必须 locate the database file ,使用 ByteArrayOutputStream 类将其转换为字节数组,将其存储在 Google Saved Games 中,然后在必要时将字节数组转换回文件。有关将文件转换为字节数组以及反之亦然的示例 see this link .

关于android - 从 SqliteDatabase 创建字节数组以使用 Google Saved Games 保存它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65037390/

相关文章:

java.lang.NullPointerException 在模拟器和手机中停止我的应用程序

java - android.database.CursorIndexOutOfBoundsException : Index -1 requested, 大小为 7

java - 有没有办法刷新 Android 中 SQLite 数据库文件的更改?

java - SQLite 上 INNER JOIN 命令的结果表名是什么

android - Google+ 登录无法正常工作

android - Google 游戏登录状态未在之前的 Activity 中共享

java - 如何使某些单词在 TextView 中可点击?

android - 从 Fragment 到 Activity 的 Intent

android - YouTube 数据 API v3 - 参数 "publishedAfter"无效

调用 takeTurn() 的 Android TurnBase Multiplayer 不会生成 onTurnBasedMatch Received()