Firebase 推送通知不使用 Android 字符串资源body_loc_key



我有一个后端服务器,将云消息推送到iOS和Android设备。在消息中,body_loc_key属性设置为someone_commented_moment, body_loc_args包含三个字符串参数。Firebase文档说明了body_loc_key:

在Android上,当填充这个值时,使用应用程序的字符串资源中的键。

在Android上,我有一个strings。xml包含这个条目:

<resources>
    [...]
    <string name="someone_commented_moment">
        @%1$s also commented on @%2$s's moment: %3$s
    </string>
    [...]
</resources>

无论如何,这个字符串资源永远不会在设备上显示的通知中加载。

在iOS上,这是完美的,我确实从通知中启动我的Activity的Intent中获得通知有效载荷,所以我想这不是服务器端的错误。我遗漏了什么吗?我是否需要手动做一些事情来使这项工作,使Firebase找到并使用通知主体本地化的字符串资源?

编辑:触发通知的python代码如下所示:

self.fcm.notify_multiple_devices(registration_ids=push_tokens,
                                 body_loc_args=notification.body_loc_args,
                                 message_body=notification.type,
                                 data_message=notification.data,
                                 body_loc_key=notification.type,
                                 sound="default")

其中self.fcm是类型为pyfcm.FCMNotification的对象,notification.type被设置为"someone_commented_moment",这是由print语句以及发送到设备的内容所确认的。

好了,我通过手动尝试对FCM服务器的不同请求找到了制造麻烦的原因。似乎Android不会在body_loc_key中使用字符串资源,如果"正常"消息体也设置-我们必须让服务器在推送到Android设备时现在离开消息体。

最新更新