Skip to content Skip to sidebar Skip to footer

Killed App Notification Click Intent Putextra Method Not Working

I have a problem intent.putExtra is not working when the app is killed. Wake up and running mode all works. I use firebase messaging service, getData() method, pending intent. priv

Solution 1:

I guess your onMessageReceived() function is not getting triggered. There are two types of notifications from firebase data messages and other one is notification message. Currently you are getting notification message which doesn't invoke onMessageReceived() in killed state. Use "data" messages instead.This could be done by the back end developer.Please ask him to send data messages. Notification messages trigger onMessageRecieved() only when app is in foreground but data message invoke onMessageRecieved() in both foreground and background state

Please replace "notification" key from payload to "data" key. Please refer to this link Click for more information

Solution 2:

Check that data first then use that

// Check if message contains a data payload.if (remoteMessage.getData().size() > 0) {
   try {
      JSONObject json = newJSONObject("{\"data\":"+remoteMessage.getData().toString()+"}");
      //decode your json data and use that
    } catch (Exception e) {
       Log.e(TAG, "Exception: " + e.getMessage());
    }
}

// Check if message contains a notification payload.if (remoteMessage.getNotification() != null) {
    String stingMessage = remoteMessage.getNotification().getBody();
    //show the message string as notification or as your want
}

To show notification and add pending intent

Intentmyintent=newIntent(this, YourActivityWantToL.class);
    myintent.putExtra("message", stingMessage);
    PendingIntentcontentIntent= PendingIntent.getActivity(this, 0, myintent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.BuildermBuilder=newNotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(TAG)
                    .setStyle(newNotificationCompat.BigTextStyle() .bigText(msg))
                    .setContentText(stingMessage);

    mBuilder.setContentIntent(contentIntent);

but if you are targeting and running app on 26 or higher you have to use notification channel

Post a Comment for "Killed App Notification Click Intent Putextra Method Not Working"