Android Notification with timestamp

사용 언어: Kotlin 1.7.0
사용 버전: Android Studio Chipmunk 2021.2.1 Patch 1

안드로이드 Notification with timestamp을 알아보겠습니다.

안드로이드 알림을 사용자에게 보여 줄 때, 언제 알림이 온 것인지 날짜가 보이게 만들어보겠습니다.


먼저, Notification을 만듭니다.


아래 문서를 보면, Android N 이상에서는 해당 옵션을 true로 설정해 줘야 보인다고 합니다. 반대로 false를 하면 숨길 수 있습니다.






그냥 사용하게 되면, 아래와 같이 알림에 시간 표시가 없습니다.





NotificationUtils.kt 파일에서 23 번째 줄처럼 builder에 setShowWhen()을 설정합니다.





Android 버전에 따라 다르지만, 알람이 몇 분 지났는지 대략적인 시간이 나타나거나 그 당시의 시각이 표현됩니다.






끝.


카테고리: Android

댓글

이 블로그의 인기 게시물

Python urllib.parse.quote()

KiCad 시작하기 7 (FreeRoute 사용하기 2)

음악 총보(Score), 파트보(Part)

Forensics .pyc 파일 .py로 복구하기

KiCad 시작하기 3 (새로운 소자 추가하기)

Kivy 시작하기 12 (Pyinstaller로 exe 파일 만들기)

딩기 요트 명칭

Android Compose automation for getting localized images to use on Play Store app image

Android Default background color setting

Android App architecture: State holders and UI state