小编TEK*_*292的帖子

EncryptedSharedPreferences 的 AutoBackUp 无法恢复

我用来EncryptedSharedPreferences在本地存储用户信息(如果您不熟悉,请参阅此)。我已经使用备份规则实现了自动备份。我备份了首选项,清除了应用程序上的数据,并尝试恢复数据(按照备份恢复概述的步骤进行操作)。

查看 Android Studio 中的设备文件资源管理器,我可以确认我的首选项文件正在恢复(它的名称正确并且其中包含加密数据)。但是,我的应用程序的功能就好像首选项文件不存在一样。

我缺少什么?

偏好代码:

class PreferenceManager(context: Context) {
    companion object {
        private const val KEY_STORE_ALIAS = "APP_KEY_STORE"
        private const val privatePreferences = "APP_PREFERENCES"
    }

    // See https://developer.android.com/topic/security/data#kotlin for more info
    private val sharedPreferences = EncryptedSharedPreferences.create(
        privatePreferences,
        KEY_STORE_ALIAS,
        context,
        EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
        EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
    )

    init {
        //val all = sharedPreferences.all
        //for (item in all) {
            //Log.e("PREFERENCES", "${item.key} - ${item.value}")
        //}
    }

    @SuppressLint("ApplySharedPref")
    fun clear() {
        // Normally you want apply, but we …
Run Code Online (Sandbox Code Playgroud)

backup android restore sharedpreferences kotlin

3
推荐指数
1
解决办法
2450
查看次数

标签 统计

android ×1

backup ×1

kotlin ×1

restore ×1

sharedpreferences ×1