设备重启后,Android推送通知 [英] Android push notifications after device reboot

查看:121
本文介绍了设备重启后,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=".common.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推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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