Android 23+ - 从备份中排除 GCM 注册 ID

标签 android google-cloud-messaging android-6.0-marshmallow android-backup-service

我有一个使用 Azure 发送推送通知的应用程序。 Azure 反过来使用 GCM 发送到 Android 设备。

我注意到我的 AndroidManifest.xml 中有警告

On SDK version 23 and up, your app data will be automatically backed up, and restored on app install. Your GCM regid will not work across restores, so you must ensure that it is excluded from the back-up set. Use the attribute android:fullBackupContent to specify an @xml resource which configures which files to backup.

我已按照此处的说明进行操作 https://developer.android.com/training/backup/autosyncapi.html?hl=in#configuring

但是我对如何从备份中排除 GCM regID 感到困惑?这是我当前的设置。

list

<application
        android:allowBackup="true"
        android:fullBackupContent="@xml/backup_scheme"
        ........

res/xml/backup_scheme.xml

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <exclude domain="sharedpref" path=""/>
</full-backup-content>

我应该把什么作为路径?我应该在我排除的地方有一个物理文件吗?

更新

所以我想我明白了。在我的 RegistrationIntentService.java 文件中,我将用户注册 ID 存储在字符串“registrationID”下的共享首选项中。所以我假设我使用以下...

<exclude domain="sharedpref" path="registrationID"/>

对吗?

最佳答案

根据@Simon 的回答进一步研究后,我认为当备份描述符 xml 文件是从 Android Studio 中的快速修复自动生成时,我们仍然需要替换 Path 中指定的文件名。我检查了我的一个应用程序中的 shared_prefs 目录,该目录已实现 Firebase 云消息传递,并找到以下 GCM 设置首选项文件:

enter image description here

因此 backup_descriptor.xml 将是:

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <!-- Exclude the shared preferences file that contains the GCM registrationId -->
    <exclude
        domain="sharedpref"
        path="com.google.android.gms.appid.xml"/>
    <exclude
        domain="sharedpref"
        path="com.google.android.gms.measurement.prefs.xml"/>
</full-backup-content>

关于Android 23+ - 从备份中排除 GCM 注册 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39088106/

相关文章:

android - 有没有在 Android Marshmallow 中以编程方式使用模式/密码解锁锁屏?

java - Android AdMob 现在显示在我的手机上

android - 具有两列和自动调整大小的图像的 Gridview

android - 在 ViewHolder 中引用 Activity

java - 从通知获取 url 并加载到 Fragment 的 webview 中的最佳方法?

android - 在Android上模拟GCM推送通知

Java Android GCM 获取 crash_key

java - 在对话框中启用 GPS 后,Android 位置返回 null

android - 在 Android M 中授予 EXTERNAL_STORAGE 所需的权限?

Android - java.lang.SecurityException : Permission Denial: starting Intent