0

I have also searched from this link. I can't find solution to show count on app launcher icon. Here is my code to show notification. How can I add fcm count on app launcher icon and solve this?

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    /*@Override
    public void onCreate() {
        super.onCreate();
        ShortcutBadger.applyCount(MyFirebaseMessagingService.this, 1);
    }*/

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        sendNotification(remoteMessage.getNotification().getBody());
    }

    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Firebase Push Notification")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

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

        notificationManager.notify(0, notificationBuilder.build());
    }
} 
KENdi
  • 7,576
  • 2
  • 16
  • 31
Peter Pan
  • 9
  • 5
  • Showing notification count in app icon is customization from OEM providers. Only Samsung, Sony like makes are providing this feature. You can not show count in all the makes. Instead, there is a new feature called notification dot introduced in oreo which supported by all OEMs. – Chandrakanth Dec 21 '18 at 05:38
  • https://stackoverflow.com/q/45064184/6701660 this might solve your problem. – Aqsa Shahid Dec 21 '18 at 07:57
  • https://stackoverflow.com/q/45064184/6701660 this might solve your problem. – Aqsa Shahid Dec 21 '18 at 07:59

0 Answers0