사용자가 정한 시간에 알람이 울리게 하는 방법에 대하여 알아보겠습니다.
이번 시간에는 알람 관련 클래스와 설정들을 만들어 보겠습니다.
- 설명 -
1. if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification을 실행하기 위해서, 안드로이드 버전이 오레오거나 이상이면 채널을 생성해야 합니다.
2. createChannel()
채널 생성 함수
3. getManager()
NotificationManager 생성 함수
4. getChannelNotification()
notification 설정 함수
class NotificationHelper(base: Context?) : ContextWrapper(base) {
private val channelID = "channelID"
private val channelNm = "channelNm"
init {
//안드로이드 버전이 오레오거나 이상이면 채널 생성
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
//채널 생성
createChannel()
}
}
//채널 생성
private fun createChannel(){
var channel = NotificationChannel(channelID, channelNm,
NotificationManager.IMPORTANCE_DEFAULT)
channel.enableLights(true)
channel.enableVibration(true)
channel.lightColor = Color.GREEN
channel.lockscreenVisibility = Notification.VISIBILITY_PRIVATE
getManager().createNotificationChannel(channel)
}
//NotificationManager 생성
fun getManager(): NotificationManager{
return getSystemService(NOTIFICATION_SERVICE) as NotificationManager
}
//notification 설정
fun getChannelNOtification():NotificationCompat.Builder{
return NotificationCompat.Builder(applicationContext, channelID)
.setContentTitle("제목")
.setContentText("알람입니다.")
.setSmallIcon(R.drawable.ic_launcher_background)
}
}
- 설명 -
1. Notification 호출해주는 클래스
class AlertReceiver: BroadcastReceiver(){
override fun onReceive(context: Context?, intent: Intent?) {
var notificationHelper: NotificationHelper = NotificationHelper(context)
var nb: NotificationCompat.Builder = notificationHelper.getChannelNOtification()
//알림 호출
notificationHelper.getManager().notify(1, nb.build())
}
}
- 설명 -
1. 알람 발생하도록 권한 등록
application 태그 위에 생성
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
2. 리시브 클래스 동작하도록 등록
application 태그 안에 생성
<!-- receiver 등록-->
<receiver android:name=".AlertReceiver"/>
2022.06.06 - [안드로이드] - [안드로이드 코틀린] 커스텀 달력 만드는 방법 part1 화면 구성
[안드로이드 코틀린] 커스텀 달력 만드는 방법 part1 화면 구성
이번 시간부터 코틀린 버전 커스텀 달력을 만들어보겠습니다. 이번 포스팅은 화면 구성입니다. 목차 1. 실행 화면 2. dataBinding 설정 3. 메인 화면 구성 activity_main.xml 1. 실행 화면 2. dataB..
aries574.tistory.com
2022.06.02 - [안드로이드] - [안드로이드 코틀린] DataBinding 컴포넌트 쉽게 접근하는 방법
[안드로이드 코틀린] DataBinding 컴포넌트 쉽게 접근하는 방법
이번 시간에는 Databinding를 통해 레이아웃 컴포넌트에 쉽게 접근하는 방법을 코틀린으로 구현해보도록 하겠습니다. 목차 1. 실행 화면 2. dataBinding 설정 3. 메인 화면 구성 activity_main.xml 4. 메인 코
aries574.tistory.com
2022.06.14 - [안드로이드] - [안드로이드 코틀린] Tab Custom Animation part1 - 화면 구성 및 설정
[안드로이드 코틀린] Tab Custom Animation part1 - 화면 구성 및 설정
앞으로 TabLayout을 직접 만들어 애니메이션 기능까지 넣어보도록 하겠습니다. 이번 시간에는 화면 구성 및 설정을 만들어 보겠습니다. 목차 1. 실행 화면 2. dataBinding 설정 build.gradle 3. 테마 변경 t
aries574.tistory.com
[안드로이드 코틀린] 정해진 시간에 알람 울리는 방법 Notification TimePickerDialog part3 - 알림 시간 표시 (0) | 2022.06.19 |
---|---|
[안드로이드 코틀린] 정해진 시간에 알람 울리는 방법 Notification TimePickerDialog part2 - 메인 화면과 메인 액티비티 (0) | 2022.06.18 |
[안드로이드 코틀린] Tab Custom Animation part3 - 탭 애니메이션 적용 (0) | 2022.06.16 |
[안드로이드 코틀린] Tab Custom Animation part2 - 탭 기능 구현 (0) | 2022.06.15 |
[안드로이드 코틀린] Tab Custom Animation part1 - 화면 구성 및 설정 (0) | 2022.06.14 |
댓글 영역