Firebase消息传递在现代Android Instant App中不起作用-是否需要DisplayNotification? [英] Firebase Messaging not Working in Modern Android Instant App - DisplayNotificationRequired?

查看:53
本文介绍了Firebase消息传递在现代Android Instant App中不起作用-是否需要DisplayNotification?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google简化了Instant Apps的创建方式之前,我已经阅读了所有与SO相关的问题,其中大多数是在2017年或2018年初回答的.就我而言,我创建了一个即时启用的应用程序捆绑包", (在此处描述)既可以作为应用程序也可以作为即时应用程序使用.

I've read all the related SO questions, most of which were asked in answered in 2017 or early 2018, before Google simplified the way Instant Apps could be created. In my case, I created an "instant enabled app bundle" (described here) that works both as an app and as an instant app.

该应用程序捆绑包包括我编写的一个库,该库被配置为接收Firebase消息(在此描述).问题在于,在运行该应用程序时会收到消息,而在运行即时应用程序时却不会收到消息.

The app bundle includes a library I wrote that is configured to receive Firebase messages (described here) from the AWS Simple Notification Service (SNS). The problem is that messages are received when the app is run, but not received when the instant app is run.

好消息是,当我查看AWS CloudWatch控制台时,可以看到每一次失败的尝试.这是消息的相关部分:

The good news is that when I look at the AWS CloudWatch console, I can see every failed attempt. Here is the relevant part of the message:

"providerResponse": "{\"results\":[{\"error\":\"InvalidParameters: DisplayNotificationRequired\"}],\"multicast_id\":\"8198293557962051\",\"success\":0,\"failure\":1,\"canonical_ids\":0}"

消息内容为:

{
"to" : "fi_Pclw7RrWtPm0xMVSgbC:APA91bGJFzM6RQVisO0N_JOAb8rUOKBVPZ0I5jh9Vf-4f-xXtbQY_Ik7q3wLGeCbR5bh_lFWDy0PX-F2mIlamMlCTIuEqEOlk0KcFO9a5fYk6B_omGqevjY6KNiByI5j_vKQaF17Rif8",
 "data" : {
     "body" : "Content message",
     "title": "the Title",  
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
     }
}

我搜索了 DisplayNotificationRequired 错误,但找不到任何内容.有人知道这意味着什么以及如何解决吗?谢谢!

I've searched for the DisplayNotificationRequired error but can't find anything. Anyone know what this means and how to fix? Thanks!

自从我写了以上内容以来,我还尝试添加一个通知对象:

Since I wrote the above, I tried adding a notification object as well:

{
"to" : "fi_Pclw7RrWtPm0xMVSgbC:APA91bGJFzM6RQVisO0N_JOAb8rUOKBVPZ0I5jh9Vf-4f-xXtbQY_Ik7q3wLGeCbR5bh_lFWDy0PX-F2mIlamMlCTIuEqEOlk0KcFO9a5fYk6B_omGqevjY6KNiByI5j_vKQaF17Rif8",
    "notification" : {
     "body" : "Content message",
     "title": "the Title"
     },
 "data" : {
     "body" : "Content message",
     "title": "the Title",  
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
     }
}

现在,我遇到 MissingDataUri 错误,而不是 DisplayNotificationRequired 错误.当我使用Postman将此消息直接发送到设备令牌时,还会收到 MissingDataUri 错误,因此我认为这不是AWS SNS或Firebase Cloud Messaging的问题,而只是一个瞬间.应用问题.

Now I'm getting an error with MissingDataUri instead of a DisplayNotificationRequired error. When I use Postman to send this message directly to the device token, I also get a MissingDataUri error, so I'm thinking this is not a AWS SNS or a Firebase Cloud Messaging issue, but just an instant app issue.

最后,我了解到有一个即时应用通知beta"回溯到2018年似乎仍在运行: https://g.co/instantapps/notifications

Finally, I understand that there was an "instant app notifications beta" way back in 2018 that appears to be still running: https://g.co/instantapps/notifications

是否仍然无法将推送通知发送到即时应用程序,特别是带有数据"有效负载的发送通知? (我继续提交了表格,以防万一.)

Is it still not possible to send a push notification to an instant app, specifically with a 'data' payload? (I went ahead an submitted the form...just in case.)

谢谢!

推荐答案

唯一的方法是将通知附加到前台服务. 即时应用目前无法进行远程通知.

The only way you can do it is with a notification attached to a foreground service. Remote notifications are currently not possible with instant apps.

我能问你为什么要这么做吗?即时应用程序应提供即时体验,并且您应假定用户将安装完整版本,或者在关闭应用程序后放弃完整版本.因此,除非将远程通知附加到体验"列表上,否则远程通知就没有多大意义.用户期望的.

Can I ask why you want to do it? An instant app should deliver an instant experience and you should assume that the user will either install the full version, or abandon it after closing the app. So remote notifications does not make much sense, unless it is attached to the "experience" the user is expecting.

如果体验需要通知流,则应使用前台服务.一个很好的例子是,如果您购买了具有队列的插入式服务(例如,理发店),并且希望在等待时间内通知用户. 在这种情况下,您可以创建带有附加通知的前台服务.该服务在后台轮询您的后端,以获取时间估计和队列位置,然后相应地更新通知.当用户完成理发操作后,您可以关闭前台服务,从而可以自动从设备中删除该应用程序.

If a notification flow is necessary for the experience, you should use a foreground service. A good example could be if you buy a drop-in service that has a queue (hairdresser for example) and you want to notify the user during the waiting time. In this case you could create a foreground service with an attached notification. The service polls your backend in the background to get a time estimate and queue position, and then update the notification accordingly. When the user is finished with his haircut, you can close the foreground service and thus allowing the app to be removed from the device automatically.

详细了解服务: https://developer.android.com/guide/components/服务

您将需要: https://developer.android.com/reference /android/Manifest.permission#INSTANT_APP_FOREGROUND_SERVICE

这篇关于Firebase消息传递在现代Android Instant App中不起作用-是否需要DisplayNotification?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆