Android push notifications after device reboot

血红的双手。 提交于 2021-02-08 11:53:22

问题


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?


回答1:


They have a background service which starts the service on bootup. You need to implement such a service. It will increase battery consumption. This might help you.




回答2:


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>


来源:https://stackoverflow.com/questions/62730314/android-push-notifications-after-device-reboot

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