2

I have created notification in my app using volley library it's calling to firebase server my problem is when i push the notification in specific user(device) the update notification only showing and unread notification count number is not showing, so i want to unread notification count number how to display in my app icon. help me ..

My code is:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG="MyMessageservice";
    RemoteMessage remoteMessage;
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage){
        String title=remoteMessage.getNotification().getTitle();
        String message=remoteMessage.getNotification().getBody();
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
       // String click_action=remoteMessage.getNotification().getClickAction();
        Intent intent=new Intent(this,VisitorList.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri notificattionSound= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this);
        notificationbuilder.setContentTitle(title);
        notificationbuilder.setContentText(message);
        notificationbuilder.setAutoCancel(true);
        notificationbuilder.setSound(notificattionSound);
        notificationbuilder.setSmallIcon(R.drawable.ic_launcher);
        notificationbuilder.setContentIntent(pendingIntent);
        notificationbuilder.setAutoCancel(true);
        notificationManager.notify(0, notificationbuilder.build());
    }
}
Anbu
  • 17
  • 1
  • 10
  • I think this function needs ROM support . AOSP doesn't support numbers in corner of icon . – cowboi-peng May 05 '17 at 08:23
  • how..?Rom and AOSP means..? – Anbu May 05 '17 at 08:38
  • I think the term you're looking for "*unread notification count number*" is *badge* count. – AL. May 05 '17 at 08:40
  • 1
    Possible duplicate of [How to display count of notifications in app launcher icon](http://stackoverflow.com/questions/17565307/how-to-display-count-of-notifications-in-app-launcher-icon) – AL. May 05 '17 at 08:40
  • @Anbu AOSP means sdk something like that , and I agree with AL . Many manufacture may implement this function ,but I don't think they will give you this priority to change this , if you have this permission , how mass the home screen will be. – cowboi-peng May 05 '17 at 08:55

1 Answers1

1

If you need to show notification count on app icon on your home screen, the function itself is not included in Android SDK by default, but every manufacture may or may not give you access to its custom api that allow that manufacture to make such functionality for example the following code work on samsung Touchwiz

Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", "your package name");
sendBroadcast(intent);

the following work on sony launcher

Intent intent = new Intent("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", count);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "your package name");
sendBroadcast(intent);

as you can see it's different code for every launcher which is kinda lame and would give you a headache Fortunately, someone gathers most of famous launchers in one library ShortcutBadger
Which, as you can find on their github the launchers they support

KUSHA B K
  • 1,489
  • 13
  • 20
Ahmed Basyouny
  • 343
  • 3
  • 11