heyou
heyou

Reputation: 335

Display Notification red badge along the App Icon

I just noticed that when i create a notification, there is no notification badge showing along the app icon on other phones that has version 4.4 and below only notification in the notif bar.

I want to display the red notification badge along the app icon on all kinds of android version just like the screenshot below:

enter image description here

Here is the code i am using to display notification, basically the user receive the notification on the notification bar but not the red badge number along the app:

private void sendNotification(NotificationVM source) {
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.putExtra(IntentPutNameConstant.NotificationActivity.NOTIFICATION_ID, source.getNotificationId());
    intent.putExtra(IntentPutNameConstant.NotificationActivity.NOTIFICATION_TYPE, source.getNotificationType());
    intent.putExtra(IntentPutNameConstant.NotificationActivity.USER_FROM_USERNAME, source.getUserFrom().getUsername());
    intent.putExtra(IntentPutNameConstant.NotificationActivity.MESSAGE, source.getMessage());
    intent.putExtra(IntentPutNameConstant.NotificationActivity.SOURCE_ID, source.getSourceId());
    intent.putExtra(IntentPutNameConstant.NotificationActivity.EXTERNAL_URL, source.getExternalUrl());

    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.ic_app_launcher_72)
            .setContentTitle("Investagrams")
            .setContentText(source.getMessage())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    //Vibration
    notificationBuilder.setVibrate(new long[] { 0, 200, 200, 200, 200, 200 });


    //LED
    //notificationBuilder.setLights(Color.RED, 3000, 3000);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notif = notificationBuilder.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;

    /*notif.ledARGB = 0xFFff0000;
    notif.flags = Notification.FLAG_SHOW_LIGHTS;
    notif.ledOnMS = 100;
    notif.ledOffMS = 100;*/

    notificationManager.notify((int)source.getNotificationId() /* ID of notification */, notif);

}

Upvotes: 0

Views: 2609

Answers (1)

Amit Shekhar
Amit Shekhar

Reputation: 3195

This is device manufacturer specific. The device which is having this features automatically do this. It calculates the total number of notification showing at that time and shows that number.

Upvotes: 1

Related Questions