티스토리 뷰

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "채널이름";
String description = "채널 디스크립션";
int 중요도 = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = null;

channel = new NotificationChannel("채널아이디", name, 중요도);
channel.setDescription (description);
//여기서 뱃지 여부 결정...
channel.setShowBadge(true);


// 시스템에 채널을 등록합니다. 중요성을 바꿀 수 없다.
// 또는이 후에 다른 알림 동작
NotificationManager notificationManager = null;

notificationManager = getSystemService (NotificationManager.class);
notificationManager.createNotificationChannel (channel);

}

중요도는 알림을 길게 클릭하면 뭐가 나오는데 그거 임.. 소리 팝업 등 설정을 컨트롤 할 수있음

 

// 우리가 설정할 수 있는 중요도는 5단계고 그중 MIN이 아주 매력적인데 노티가 얇음 .. 마음에 들더라

 

채널 아이디는 노티 만들떄 아래와 같이 똑같아야 한다.

 

근데 이 채널이 한번 만들어지면 안드에서 재사용을 하는지 설정을 바꿔줘도 바뀌지가 않더라 이거때문에 좀 빡쳤는데

 

카카오톡도 컨트롤 못했어서 좀 풀림 ( 앱 설정에서 알림 끄고 노티 알림 켜면 알림 신나게 울림 )

 

디스크립션은 앱에서 길게 클릭하면 무슨 채널인지 설명? 할 수 있는 친절한 문구 셋해주는거..

 

하여튼 이렇게 채널을 만들어 준다...

 

 

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(this, SettingSecurityActivity.class));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
PendingIntent contentIntent = PendingIntent.getActivity(this, 3, intent, PendingIntent.FLAG_UPDATE_CURRENT);

final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder (this, "채널뭔데")
.setSmallIcon (R.drawable.ic_call_send_big)
.setContentTitle ("타이틀")
.setContentText ("내용텍스트")
.setContentIntent(contentIntent)
.setPriority (NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setBadgeIconType(1)
.setNumber(121);
//이 넘버는 각자의 넘버로...

final NotificationManagerCompat notificationManager = NotificationManagerCompat.from (SettingSecurityActivity.this);
notificationManager.notify (123, mBuilder.build());

 

이렇게 펜딩인텐트와 노티를 만들어 준다..

 

 

디벨로퍼 사이트를 보니

 

contentTitle이랑 contentText랑 SmallIcon이 필수란다

 

이전엔 리모트뷰를 만들어 넣었어서 저 세개가 필요가 없었는데

 

저 세개를 안넣어서 뱃지가 안나오는 괴상망측한 상황이 발생했었다.

 

setBadgeIconType은 뱃지의 크기라는데 ... 차이가 없던데

 

하여튼 setNumber로 뱃지를 만들어 준다.

 

 

NotificationCompat.Builder 가 안될 땐

 

 

final Notification n = new Notification.Builder(mContext, nid)
.setContentIntent(contentIntent)

.setContentTitle (msg)
.setContentText("")
.setBadgeIconType(BADGE_ICON_LARGE)
.setSmallIcon (R.mipmap.ic_launcher)
.setNumber(숫자)
.setAutoCancel(true).build();

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from (mContext);
notificationManagerCompat.notify (nid, n));

이걸로 해보길..

 

난 위에껄로 안되고 이걸로 됨

 

위에걸로 따로 프로젝트 만들어서 헀을땐 됐는데...

 

 

 

오레오 극혐