设备重启后,Android推送通知

编程入门 行业动态 更新时间:2024-10-25 12:18:27
本文介绍了设备重启后,Android推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用FirebaseMessagingService处理传入的通知.当我的应用程序处于前台和后台时,消息将到达.当我滑出应用程序时,通知即将到达.但是,如果我重新启动设备,则直到运行我的应用程序时才会收到通知.以同样的方式,Telegram和WhatsApp在重新启动后继续接收通知.我已经实现了onNewToken()方法,并添加了将新令牌发送到服务器的逻辑,但这并没有帮助.重新启动后如何继续接收通知?

I use the FirebaseMessagingService to handle incoming notifications. When my app is in the foreground and background the messages are being arrived. When I swipe-out the app, notifications are being arrived. But if I restart my device, notifications are not being arrived until I run my app. In the same way, Telegram and WhatsApp continue receiving notifications after reboot. I have implemented the onNewToken() method and have added logic to send new token to the server but it hasn't helped. How can I continue receiving notification after reboot?

推荐答案

实际上,如果要在重新启动后启动服务,则必须添加意图过滤器操作.尝试在您的意图过滤器中添加BOOT_COMPLETED操作.在清单中添加以下行.但基本上对于Firebase Notification,无需添加此操作.

Actually, If you want to start service after restarted then you have to add intent-filter action. try to add BOOT_COMPLETED action in your intent-filter. Add below lines in the manifest. But basically for Firebase Notification, No need to add this action.

<service android:name="mon.service.NotificationService" android:enabled="true" android:exported="true" android:permission="android.permission.BIND_JOB_SERVICE" android:process=":notification_service"> <intent-filter> <action android:name="com.abc.xyz.restart_service" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

更多推荐

设备重启后,Android推送通知

本文发布于:2023-11-27 01:52:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重启   通知   设备   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!