Hi friends,
I am facing some problem in push notification. When i am using my and at that time if any notification is coming then message text is visible, but when my app is in background then message text is not coming. Can any one help for this??
Thanks
What I have tried:
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Data = remoteMessage.getData();
message1=Data.get("message");
note_id=Data.get("NoteId");
l = Long.parseLong(note_id);
DataBaseHelper myDBHelper = new DataBaseHelper(getApplicationContext());
myDBHelper.open();
objGCM.NOTEID=l;
objGCM.MESSAGE=message1;
i=myDBHelper.InsertgcmRecord(objGCM);
gcmList.add(objGCM);
myDBHelper.close();
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
sendNotification(message1);
}
private void sendNotification(String message) {
Intent intent = new Intent(this, NotificationList.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestID , intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notnullogo)
.setContentTitle("NotNul")
.setContentText(message1)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setColor(Color.parseColor("#0089C4"))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message1))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}