20230626 작성중
Compat : Compatability의 줄임말. 안드로이드에서 Compat은 호환성을 의미한다.
안드로이드 플랫폼은 버전마다 API수준이 다르며 새로운 기능과 API가 추가되는 경우가 많다. 따라서 앱을 개발할 때 호환성을 고려하여 다양한 안드로이드 버전에서 동일한 동작을 보장해야 한다.
Compat관련 클래스와 패키지는 호환성 지원을 위해 안드로이드에서 제공되는 클래스.
개발자는 호환성 지원을 위해 Compat클래스들을 사용해서 안드로이드 버전에 관계없이 동일한 기능을 제공할 수 있다.
IconCompat : 호환성을 갖는 아이콘 지원 클래스로서, 다양한 안드로이드 버전에서 일관된 방식으로 아이콘을 사용할 수 있게 도와준다.NotificationCompat : 호환성을 갖는 알림 지원 클래스로서, 다양한 안드로이드 버전에서 일관된 방식으로 알림을 생성하고 관리할 수 있도록 도와준다.=> 새로운 기능이나 API 변경으로 인해 발생하는 호환성 문제를 최소화
getSystemService(NOTIFICATION_SERVICE) - 알림 관리 시스템 서비스 추출
NotificationCompat.Builder(context: Context, id: ChannelId) - 채널을 이용해 빌더 생성
알림 기능을 관리하는 시스템 서비스
getNotificationChannel(channelid: Int) - 채널id로 NotificationChannel 객체 추출
createNotificationChannel(channel: NotificationChannel) - NotificationManager에 채널 등록
notify(id: Int, notification: Notification) - 알림 표시
cancel(id: Int) - 알림 취소
알림 채널
NotificationChannel(id: Int, name: CharSequence, importance: Int) - NotificationChannel 생성자
enabledLights(lights: Boolean) - LED 램프 사용 여부
lightColor - LED 램프 색상
enabledVibration(vibration: Boolean) - 진동 사용 여부
description - 메시지
setSmallIcon()
setLargeIcon()
setNumber()
setContentTitle()
setContentText()
setAutoCancel(b: Boolean) - 알림을 터치할 때 사라지는 여부 설정
setOngoing(b: Boolean) - 알림을 스와이프할 때 사라지는 여부 설정
build() - 빌더로 Notification 객체 생성
Activity에서 Notification을 발생시키는 경우는 잘 없고, 주로 BroadcastReceiver나 Service에서 Notification을 발생시키고 알림을 누르면 Activity를 실행토록 하는 게 일반적이다.
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.img_android)
Bitmap vs Drawable
Bitmap : 보여주기용 이미지
Drawable : 편집 가능한 이미지
decodeResource
resources