사실 해당 포스팅에는 글 길게 보이게 하는 설정 하나면 충분 하지만,
기본적으로 푸쉬에 필요한 코드부터 작성했으니 참고하면 된다.
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); //푸쉬 노티피케이션 클릭 시 자동 삭제 여부
앱 알림들을 살펴보면 위 텍스트 스타일 설정을 해서 글을 무작정 다 보여주지는 않는 게 대부분 인 것 같다.
보통...로 처리하고 끝!
EditText , TextView addTextChangedListener 이벤트 추가하기 (0) | 2020.11.26 |
---|---|
안드로이드 텍스트 색상 부분 적용하기 (0) | 2020.11.24 |
오늘 날짜 구하기, 연, 월, 일, 시간 응용 해보기 (0) | 2020.11.24 |
자바코드를 코틀린으로 변경하기 (0) | 2020.11.23 |
java.io.NotSerializableException 오류 (0) | 2020.11.23 |
댓글 영역