1. Importance
채널 생성에 앞서 Importance에 따른 채널 중요도를 설정할 수 있다.
여기서 중요한 점은 헤드업 알람의 유무
2. 인자
id : 임의의 채널 id
name : 알람 이름
importance level : 알람 중요도
3. 순서
Channel과 NotificationManager 초기화 후 마지막에 .createNotificationChannel을 해야한다.
4. 코드
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription("channel description");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.GREEN);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 100, 200});
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(notificationChannel);
}
5. 옵션
무음
mChannel.setSound(null, null);
mChannel.setVibrationPattern(new long[]{0});
mChannel.enableVibration(false);
소리
int notificationId = 0;
final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mCompatBuilder = new NotificationCompat.Builder(context);
Uri alertSound;
if (com.ucware.util.Config.sharedInstance().enablePushSoundConfig) {
int res_id = com.ucware.util.Config.sharedInstance().getPushSoundResourceId(context);
alertSound = Uri.parse("android.resource://" + context.getPackageName() + "/" + res_id);
} else {
alertSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
mCompatBuilder.setSound(alertSound);
nm.notify(notificationId, mCompatBuilder.build());
'Android > Android Java' 카테고리의 다른 글
[Android Java] 모션레이아웃을 이용한 드래그시 숨기기/나타나기 (0) | 2023.10.27 |
---|---|
[Android Java] 터치시 사라지는 상하단바(애니메이션, 터치리스너) (0) | 2023.10.27 |
[Android Java] 오디오모드(벨모드,진동모드,무음모드) (0) | 2023.10.27 |
[Android Java] 진동 세기 및 패턴 (0) | 2023.10.27 |
[Android Java] 애니메이션 만들기 (0) | 2023.10.27 |