Android Notification Using FCM

后端 未结 1 425
-上瘾入骨i
-上瘾入骨i 2020-12-07 05:46

I\'m having an issue with data from the notification when the app is killed data the data which is sent from intent is getting null else if when the app is running I\'m able

相关标签:
1条回答
  • 2020-12-07 06:27

    Change your request body this like:

    { 
    "data":{
        "title" : "your_title",
        "body" : "your_body" 
    }, 
      "to": "device_token",
      "priority": "high" 
    }
    

    and onMessageReceived:

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    
            String title = remoteMessage.getData().get("title");
            String body = remoteMessage.getData().get("body");
            sendNotification(title,body); // edit for your self
        }
    }
    

    now it works when app killed, background and foreground

    0 讨论(0)
提交回复
热议问题