Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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());
}
Posted
Updated 4-Sep-16 23:32pm

1 solution

The code included doesn't include a broadcast receiver, can't really help without seeing the complete code.

/Darren
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900