如何使用Python Firebase Admin SDK通过FCM发送带深度链接的消息
问题原因
你当前的Python代码仅配置了Web推送场景的跳转链接,没有针对安卓平台做对应的跳转逻辑配置,导致安卓端无法识别深度链接跳转规则。
修复方案
新增安卓平台专属的通知配置,指定点击跳转的深度链接,再将配置加入多播消息参数即可,修改后的完整代码如下:
from firebase_admin import messaging _notification= messaging.Notification( body=self.message_body(), title=self.message_title(), image=self.__image, ) web_notification = messaging.WebpushNotification( body=self.message_body(), title=self.message_title(), image=self.__image, ) _option = messaging.WebpushFCMOptions( link=self.__link ) _web = messaging.WebpushConfig( fcm_options=_option, notification=web_notification ) # 新增安卓平台配置 _android_notification = messaging.AndroidNotification( title=self.message_title(), body=self.message_body(), image=self.__image, click_action=self.__link ) _android_config = messaging.AndroidConfig( notification=_android_notification ) _message = messaging.MulticastMessage( notification=_notification, tokens=_sending_token, webpush=_web, android=_android_config )
注意事项
如果你的深度链接使用自定义scheme(非http/https),直接将click_action的值替换为对应的自定义scheme链接即可,同时需要确保安卓端AndroidManifest.xml中对应跳转页面的intent filter已经正确注册了对应域名或scheme的匹配规则,示例规则如下:
<intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" android:host="url.com" /> </intent-filter>
内容的提问来源于stack exchange,提问作者Mohsen Haydari
相关产品推荐
相关产品推荐

