I will try to handle firebase notification when device screen off means wake up the device when a notification arrives. In my project notification divide into so may state so how I can wake up device programmatically whenever required. May also use wake lock, but when screen off then actually
@Override
public void onMessageReceived(RemoteMessage message) {
}
This method not called so in this circumstances so how I can wake up the device? Can any buddy help me with this issue?
There are two types of messages in FCM (Firebase Cloud Messaging):
Notification Messages: These messages trigger the onMessageReceived() callback only when your app is in foreground
Data Messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed
NOTE: Be sure you're not adding JSON key notification
The following message will not call your onMessageReceived() when your app is in the background or killed, and you can't customize your notification.
{
"to": "example",
"notification": {
"title" : "title",
"text": "text"
}
}
but instead using this will work
{
"to": "example",
"data": {
"text":"text",
"title":"title"
}
}