【问题标题】:How to specify to not allow any data backup with android:dataExtractionRules?如何指定不允许使用 android:dataExtractionRules 和
【发布时间】:2022-07-25 07:49:02
【问题描述】:

我当前的 android 应用程序面向 12 或更高版本。

我不想允许任何类型的备份,并且目前有这些清单设置

    android:allowBackup="false"
    android:fullBackupContent="false"
    

但是android:allowBackup="false" 设置现在给出以下警告

The attribute android:allowBackup is deprecated from Android 12 and higher and may be removed in future versions. Consider adding the attribute android:dataExtractionRules specifying an @xml resource which configures cloud backups and device transfers on Android 12 and higher.

我查看了 android:dataExtractionRules xml 的示例,但没有一个显示如何配置 allowBackup="false" 的等效项。

我错过了什么?

使用android:dataExtractionRules xml是否可以实现allowBackup="false"

【问题讨论】:

    标签: android android-manifest


    【解决方案1】:

    dataExtractionRules 属性添加到您的 AndroidManifest.xml 文件中,并引用 data_extraction_rules.xml 文件:

    <application
        android:allowBackup="false"
        android:fullBackupContent="false"
        android:dataExtractionRules="@xml/data_extraction_rules"
        ...>
    

    然后,为云备份和d2d 传输排除所有可能的域,更新或创建文件app/src/main/res/xml/data_extraction_rules.xml

    <?xml version="1.0" encoding="utf-8"?>
    <data-extraction-rules>
        <cloud-backup>
            <exclude domain="root" />
            <exclude domain="file" />
            <exclude domain="database" />
            <exclude domain="sharedpref" />
            <exclude domain="external" />
        </cloud-backup>
        <device-transfer>
            <exclude domain="root" />
            <exclude domain="file" />
            <exclude domain="database" />
            <exclude domain="sharedpref" />
            <exclude domain="external" />
        </device-transfer>
    </data-extraction-rules>
    

    dataExtractionRules 属性 is available 用于 API 31 (Android 12) 及更高版本。为 API 31 之前的 Android 版本保留 allowBackupfullBackupContent 属性。

    注意可能使“Attribute dataExtractionRules is only used in API level 31 and higher (current min is 19)”警告静音,同时带有tools:targetApi="s" 属性(因为旧平台只是忽略它们不支持的清单属性和警告没用)。

    【讨论】:

    • The docs 说“如果指定&lt;include&gt; 元素,系统默认不再包含任何文件,只备份指定的文件”。有没有人尝试过像&lt;device-transfer&gt;&lt;include domain="" tools:ignore="FullBackupContent" /&gt;&lt;/device-transfer&gt;这样的东西?
    猜你喜欢
    • 2022-06-11
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2013-07-19
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多