Phi*_*hil 16 android google-cloud-messaging android-backup-service android-6.0-marshmallow
我有一个使用Azure发送推送通知的应用程序.Azure依次使用GCM发送到Android设备.
我注意到我的AndroidManifest.xml中有一个警告说明
在SDK版本23及更高版本中,您的应用数据将自动备份,并在应用安装时恢复.您的GCM注册表无法在恢复期间使用,因此您必须确保将其从备份集中排除.使用属性android:fullBackupContent指定一个@xml资源,该资源用于配置要备份的文件.
我按照https://developer.android.com/training/backup/autosyncapi.html?hl=in#configuring中的说明进行操作
但是我对如何从备份中排除GCM regID感到难过?这是我目前的设置.
表现
<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_scheme"
........
Run Code Online (Sandbox Code Playgroud)
RES/XML/backup_scheme.xml
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path=""/>
</full-backup-content>
Run Code Online (Sandbox Code Playgroud)
我把什么作为路径?我应该在某个地方放置一个物理文件吗?
UPDATE
所以我想我明白了.在我的RegistrationIntentService.java文件中,我将用户registrationID存储在字符串"registrationID"下的共享首选项中.所以我假设我使用以下内容......
<exclude domain="sharedpref" path="registrationID"/>
Run Code Online (Sandbox Code Playgroud)
对?
从@Simon答案进一步研究之后,我认为Path当从Android Studio中的quickfix自动生成备份描述符xml文件时,我们仍然需要替换在指定的文件名。我检查了其中一个已实现Firebase Cloud Messaging的应用程序中的shared_prefs目录,并找到了以下GCM设置首选项文件:
因此,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>
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题而且我会接受接受答案,但事实证明它似乎不应该做什么.
我做的是在创建backup_scheme.xml文件之前在清单中设置fullBackupContentProperty.当然,Android Studio抱怨警告,但为我提供了一个自动生成该文件的quickfix.
应用quickfix生成以下文件:
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- Remove the following "exclude" elements to make them a part of the auto backup -->
<exclude
domain="database"
path="attendee.db" />
<exclude
domain="database"
path="whova_messages.db" />
<exclude
domain="database"
path="photo.db" />
<exclude
domain="database"
path="agenda.db" />
<exclude
domain="database"
path="ebb.db" />
<exclude
domain="database"
path="vertical.db" />
<exclude
domain="database"
path="whova.db" />
<!-- Exclude the shared preferences file that contains the GCM registrationId -->
<exclude
domain="sharedpref"
path="WhovaMessagePrefFile.xml" />
<exclude
domain="sharedpref"
path="APP_RATER.xml" />
<exclude
domain="sharedpref"
path="WhovaPrefFile.xml" />
</full-backup-content>
Run Code Online (Sandbox Code Playgroud)
请注意 <!-- Exclude the shared preferences file that contains the GCM registrationId -->
所以我的猜测是你必须排除包含GCM ID的整个共享首选项文件,而不仅仅是密钥.
太糟糕了,文档不会让它变得非常清晰,也太糟糕了,我们不得不从备份中排除整个文件.
所以我明白了.在我的RegistrationIntentService.java文件中,我将用户registrationID存储在字符串"registrationID"下的共享首选项中.所以在backup_scheme.xml文件中使用以下内容...
<exclude domain="sharedpref" path="registrationID"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2874 次 |
| 最近记录: |