Reputation: 1287
I have implemented FCM push notification in my android application. Push notifications are received under normal circumstances. My scenario is:
FirebaseInstanceId.getInstance().getToken()
Shouldn't the phone receive the notification the phone is switched on. I tested FCM for another scenario.
FirebaseInstanceId.getInstance().getToken()
Why is FCM notification not received when device is just booted?
Upvotes: 4
Views: 2172
Reputation: 2198
I think you should repeat this scenario on different devices, because some devices have special settings by default, like not letting background app to autostart or access internet unless explicitly allowed. So, maybe it is device specific, for example if you don't get notification when app is not open in foreground or is available in recent apps, then it is the case.
Other than this, I think you should add RECEIVE_BOOT_COMPLETED
permission in your manifest and initialize your app on receiving boot complete
broadcast, so as it doesn't get killed on device power off and its services restart when device switched on.
I am having several apps with GCM push notification on a phone and this phone runs out of battery very frequently but each time I switched it on again, I receive all the notifications which were sent when phone was offline. So I think that there is something missing in your scenario and it should receive notifications when it switched on.
Upvotes: 3
Reputation: 2932
The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token. Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh, and log the value as shown:
You have to make sure thatonTokenRefresh method override in your MyFirebaseInstanceIDService
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken); // Replace this method with your appropriate method for send registration token to server
}
Upvotes: 2