Adil Mahmud Choudhury Adil Mahmud Choudhury - 9 days ago 9
Android Question

Notification Not showing

Case study: I need a program that will add a notification at android. And when someone click on the notification it should lead them to my second activity.

I have established a code. The notification should be working, but for some reason it is not working. The

Notification
isn't showing at all. Dont know what am i missing.

Code of those files:

Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setContentIntent(pIntent).setAutoCancel(true)
.setStyle(new Notification.BigTextStyle().bigText(longText))
.build();

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Hide the notification after its selected

notificationManager.notify(0, n);

Answer

As @dmmh said the code wont work without and icon. So after modifying the code with

.setSmallIcon(R.drawable.icon)

the project run perfectly.