如何在应用启动器图标中显示fcm通知的计数?

时间:2018-12-21 05:13:58

标签: android firebase firebase-cloud-messaging badge

我也从这个link中进行了搜索。我找不到能在应用启动器图标上显示数量的解决方案。这是我显示通知的代码。如何在应用启动器图标上添加fcm计数并解决此问题?

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());
    }
} 

0 个答案:

没有答案