I need your help , i went to the google and searched alot,I am facing serious issue when my app is in background and i send the notification from the backened then the notification is coming but it not load the data when i make my app from background to forground,if i touch the notification icon then i am getting the data.
I went to this link also How to handle notification when app in background in Firebase
There guys are telling you have to click the notification icon to load a data , what is an alternative of FCM.
I tried :
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.v(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
// if (remoteMessage.getData().size() > 0) {
// Log.v(TAG, "Message data payload: " + remoteMessage.getData().get("order"));
//
// }
// if (remoteMessage.getNotification() != null) {
// Log.v(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
//
// }
sendNotification(remoteMessage.getData().get("order"));
}
private void sendNotification(String messageBody) {
Log.e("inside sendNotification","sendNotification");
JSONObject jobj_order= null;
try {
dbHelper=new DBHelper(this);
jobj_order = new JSONObject(messageBody);
dbHelper.insertOrder(jobj_order.getJSONObject("supplier").toString(),jobj_order.getJSONObject("request").toString(),jobj_order.getString("expiry"),jobj_order.getString("id"),jobj_order.getString("quantity"));
Log.e("inside try block","inside try block");
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(MainActivity.NOTIFY_ACTIVITY_ACTION );
broadcastIntent.putExtra("reload", true);
sendBroadcast(broadcastIntent);
} catch (JSONException e) {
e.printStackTrace();
}
MainActivity.isNotification=true;
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.splash_logo)
.setContentTitle("Logizo")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}