1

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?

FreakyAli
  • 10,567
  • 3
  • 19
  • 50
Kishan Donga
  • 2,423
  • 1
  • 20
  • 33

1 Answers1

4

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"
       }
    } 
Tufan
  • 3,384
  • 4
  • 32
  • 53
  • your ans proper but if my notification structure have both tag like notification and data in that case notification will be weak up device or not? – Kishan Donga Jun 14 '17 at 13:17
  • it will not work check i already told (Be sure you're not adding JSON key notification) and if answer is okay than accept it as a answer so others will also get benifit – Tufan Jun 14 '17 at 13:22