问题
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