Firebase push notification doesn't use Android string resource from body_loc_key

旧街凉风 提交于 2021-01-27 21:21:38

问题


I have a backend server that pushes cloud messages to iOS and Android devices. In the messages, the body_loc_key attribute is set to someone_commented_moment, and body_loc_args contains three string arguments. The Firebase documentation says about the body_loc_key:

On Android, use the key in the app's string resources when populating this value.

So on Android, I have a strings.xml which contains this entry:

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

Regardless, this string resource is never loaded in the notification that is shown on the device.

On iOS this works flawlessly, and I do get the notification payload in the Intent that starts my Activity from the notification, so I suppose it's not an error on the server side. Am I missing something here? Do I have to manually do something to make this work, to make Firebase find and use that string resource for the localization of the notification body?

Edit: The python code triggering the notification looks like this:

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")

Where self.fcm is an object of type pyfcm.FCMNotification, and notification.type is set to "someone_commented_moment", as is confirmed by a print statement as well as by what gets sent to the device.


回答1:


Alright I found what was making the trouble, by manually trying different requests against the FCM server. It seems that Android won't use the string resource in the body_loc_key if the "normal" message body is also set - we have to let the server leave out the message body now when pushing to an Android device.



来源:https://stackoverflow.com/questions/39319612/firebase-push-notification-doesnt-use-android-string-resource-from-body-loc-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!