오레오 이전 버전에서는 FirebaseMessagingService를 상속받은 클래스에서 onMessageReceived 안에 아래 코드의 방식으로 Badge count를 app icon에 보여주었는데
Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
badgeIntent.putExtra("badge_count", count);
badgeIntent.putExtra("badge_count_package_name", getPackageName());
badgeIntent.putExtra("badge_count_class_name", launcherClassName);
sendBroadcast(badgeIntent);
오레오 버전에서는 badge관련 기능이 생겼다고 들어서 위의 코드를 수행하지 않고
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannelGroup group = new NotificationChannelGroup(groupId, groupName);
notificationManager.createNotificationChannelGroup(group);
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(channelDescription);
channel.setGroup(groupId);
channel.enableLights(true);
channel.setLightColor(getColor(R.color.red));
channel.enableVibration(true);
channel.setShowBadge(true);
channel.setSound(defaultSoundUri, null);
channel.setVibrationPattern(new long[]{100, 200, 100, 200});
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
if (!isCreateChannel(this, channelId)) {
Log.e("채널생성");
setCreateChannel(this, channelId, true);
notificationManager.createNotificationChannel(channelMessage);
} else {
DebugLog.e("채널생성X");
}
Notification notification = new Notification.Builder(this, channelMessage.getId())
.setSmallIcon(getNotificationIcon())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle(title)
.setContentText(content)
.setGroupSummary(true)
.setAutoCancel(true)
.setChannelId(channelMessage.getId())
.setColor(getColor(R.color.select_color2))
.setContentIntent(pendingIntent)
.setBadgeIconType(BADGE_ICON_SMALL)
.setNumber(badgeCount)
.setStyle(new Notification.BigTextStyle()
.setBigContentTitle(title)
.bigText(content))
.build();
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(notification_id, notification);
위의 코드를 실행하는데 푸시는 오지만 badge가 생성이 안되네요..
https://github.com/leolin310148/ShortcutBadger 와 같은 라이브러리를 이용해서 badge를 보여줄수 있는건가요?