마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

오레오 버전에서의 notification badge에 대해 질문드립니다.

0 추천

오레오 이전 버전에서는 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를 보여줄수 있는건가요?

aaaandhelper (900 포인트) 님이 2018년 5월 29일 질문
aaaandhelper님이 2018년 5월 30일 수정

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...