如果用户更改设备或再次安装应用程序时,async存储值要持续下去怎么办?
您不会相信它,但是它可以与Android一起使用!
首先,我们需要在android/app/src/main/AndroidManifest.xml
文件中启用备份选项:
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/backup_rules"
文档:koude1
然后创建具有应添加到备份的文件列表的android/app/src/main/res/xml/backup_rules.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup>
<!-- your rules -->
</cloud-backup>
<device-transfer>
<!-- your rules -->
</device-transfer>
</data-extraction-rules>
测试
下面列出了更多规则,但首先,让我们看一下如何测试它们。
- 您可以使用模拟器或真实设备
- 需要启用备份:
Setting
=>System
=>Backup
5 - 然后使用
adb
您可以创建/还原备份:
# Replace `com.mycompany.myapp` with your app package!!!
adb shell bmgr backupnow com.mycompany.myapp # Create backup
adb shell bmgr restore 1 com.mycompany.myapp
# ^^^ use a fake id `1` to show list of available sets
# No matching restore set token. Available sets:
# 3a945fc11efadf47 : Google Pixel 7 Pro
# done
adb shell bmgr restore 3a945fc11efadf47 com.mycompany.myapp # Now use a real id, to restore backup
规则
我为您的方便起见为最受欢迎的本机包制定了一系列准则。
<include domain="database" path="RKStorage"/>
<include domain="database" path="RKStorage-journal"/>
SharedPreferences.setName("my_name"); // js part
<include domain="sharedpref" path="my_name.xml" /> // android part
<include domain="file" path="./mmkv" />
koude10 cookies
<include domain="root" path="./app_webview"/>
<include domain="file" path="./default.realm" />
<include domain="file" path="./default.realm.lock" />
<include domain="file" path="./default.realm.management" />
<include domain="file" path="./default.realm.note" />
<include domain="root" path="./watermelon.db"/>
<include domain="root" path="./watermelon.db-wal"/>
<include domain="root" path="./watermelon.db-shm"/>
如何创建自己的规则
adb shell
run-as com.mycompany.myapp # Replace `com.mycompany.myapp` with your app package!!!
find . -type f # will print all files
# 1) For files in directory `./files/*`
# <include domain="file" path="./mmkv" />
# ^^^^^^ ./files/mmkv
# 2) For `./shared_prefs/*.xml`
# <include domain="sharedpref" path="my_name.xml" />
# ^^^^^^^^^ ./shared_prefs/my_name.xml
# ...