상세 컨텐츠

본문 제목

안드로이드 푸쉬 노티피케이션(알림) 글 길게 보이게 하기

안드로이드/코틀린, 자바

by 개발익선 2020. 11. 23. 17:51

본문

사실 해당 포스팅에는 글 길게 보이게 하는 설정 하나면 충분 하지만,

기본적으로 푸쉬에 필요한 코드부터 작성했으니 참고하면 된다.

 

private final static String CHANNEL_ID_NOTI = "notification";

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.img_app); // 푸시 아이콘 넣기

NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

NotificationCompat.Builder notificationBuilder;

 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //Oreo 버전 이상일 경우
 NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_NOTI,  push_message, NotificationManager.IMPORTANCE_DEFAULT); //push_message : 푸시 메시지 넣기(String)
 nm.createNotificationChannel(notificationChannel);
 notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID_NOTI);
} else {
 notificationBuilder = new NotificationCompat.Builder(this);
 //notificationBuilder.setVibrate(new long[]{0l}); //휴대폰 진동
}

 

notificationBuilder.setContentTitle(app_name); // 타이틀 설정

 

notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); //텍스트를 drop down으로 짧게 또는 길게 보일 수 있도록 설정


notificationBuilder.setContentText(message); //푸쉬 노티피케이션 내용
notificationBuilder.setLargeIcon(largeIcon); //푸쉬 노티피케이션 아이콘
notificationBuilder.setAutoCancel(true); //푸쉬 노티피케이션 클릭 시 자동 삭제 여부

 

앱 알림들을 살펴보면 위 텍스트 스타일 설정을 해서 글을 무작정 다 보여주지는 않는 게 대부분 인 것 같다.

보통...로 처리하고 끝!

 

관련글 더보기

댓글 영역