Hi DW.

I'm developing an App that uses the FCM notification, but the problem is that my code doesn't seem to get the actual data like when I extract the message or body it shows just the icon only if the notification was received when the App is open, and it shows the title and body if the notification is received when the App is not running.

Basically what I'm trying is to get the message and put that on a textView so that it is seen on the actual App when you click the notification.

Here is my FirebaseMessagingService code:

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {

    public void onMessageReceived(RemoteMessage remoteMessage) {

    private void showNotification(String message) {
        Intent i = new Intent(this,MainActivity.class);
        //if(message != "") {
        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentText(message).setLights(Color.GREEN, 300, 300)
                .setVibrate(new long[] { 100, 250 })
                // .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);



My MainActivity code:

protected void onCreate(Bundle savedInstanceState)  {
        // remove title
       /* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

        txtStatus = (TextView) findViewById(R.id.txtStatus);
if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("message")) {

    Intent intent = new Intent(MainActivity.this,Main3Activity.class);
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    String mmsg = "9";
    if (extras != null) {
        for (String key : extras.keySet()) {
            Object value = extras.get(key);
            //Log.d(Application.APPTAG, "Extras received at onCreate:  Key: " + key + " Value: " + value);
            mmsg = extras.getString("message");
        //String title = extras.getString("title");

        if (mmsg != null && mmsg.length() > 0) {

    intent.putExtra("nmsg", mmsg);
txtStatus.setText("Not set");

    ctoken = FirebaseInstanceId.getInstance().getToken();

    String data = "action=check&token=" + ctoken;
    goData = data;
    new MainActivity.MakeNetworkCall().execute("http://my_server_url" + data, "Post");
//    txtStatus.setText("Please wait...");



my server script that sends notifications to FCM and down to the App code:


    $payload = array(
                      "title"=> 'Alert title',
                      "body"=> 'This is a body message.',
                      "sound"=> "default",
                      "message"=> "This is the main message"
    $headers = array(
      'Content-Type: application/json'
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $payload ) );
    $result = curl_exec($ch );
    curl_close( $ch );

I've managed to figure out what was the problem. The data array didn't have the message so putting the message inside it solved the problem

 'message'=>'My message here',
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.