If you use the console to send notification, it is not considered as payload, so if the application is running in background, the method onMessageReceived() is not called. But if the app run in foreground it does.
Here is a curl command to send a notification via curl as payload, you have to use a shell to use it.
curl -X POST --header "Authorization: key=<APIKEY>" --Header "Content-Type:
application/json" https://fcm.googleapis.com/fcm/send -d '{"to":"<YourToken>","data":{"type":"notification","message":"Hello, it works"}}'
**Note: remove the <>.
Your onMessageReceived() method looks like this to get the data.
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
try {
String remote_type = remoteMessage.getData().get("type");
if (remote_type.equals("notification")){
String message = remoteMessage.getData().get("message");
Log.d("ReceivedData", message);
}
}catch(NullPointerException e){
}