Kapil Rajput
Kapil Rajput

Reputation: 11545

Why Android Notification not works if setSmallIcon is Missing?

My doubt is why Notification is not build if setSmallIcon is missing in code :

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
//  builder.setSmallIcon(R.drawable.ic_launcher);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"));
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

        builder.setContentIntent(pendingIntent);
        builder.setContentTitle("Google");
        builder.setContentText("Go to Google");
        builder.setSubText("Tap to go to link in notifications.");

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, builder.build());

app dont throws any Exception, code run's fine but Notification is not showing and if i uncomment

builder.setSmallIcon(R.drawable.ic_launcher);

app Notification Works fine so my Question is why builder.setSmallIcon is compulsory to show a Notification. And if I don"t want to show smallicon on status bar any Solution ?

Upvotes: 0

Views: 1196

Answers (1)

M D
M D

Reputation: 47817

It's because .setSmallIcon(R.drawable.ic_launcher); it's an pre requirement. If you're using NotificationCompat.Builder. I read some where in Google Developers Blog.

Upvotes: 4

Related Questions