class
AlarmReceiver: BroadcastReceiver() {
companion object {
const
val NOTIFICATION_ID =
100
const
val NOTIFICATION_CHANNEL_ID =
"1000"
}
override fun onReceive(context: Context, intent: Intent) {
createNotificationChannel(context)
notifyNotification(context)
}
private
fun createNotificationChannel(context: Context) {
if
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel = NotificationChannel(
NOTIFICATION_CHANNEL_ID,
"기상 알람"
,
NotificationManager.IMPORTANCE_HIGH
)
NotificationManagerCompat.from(context).createNotificationChannel(notificationChannel)
}
}
private
fun notifyNotification(context: Context) {
with(NotificationManagerCompat.from(context)) {
val build = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setContentTitle(
"알람"
)
.setContentText(
"일어날 시간입니다."
)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setPriority(NotificationCompat.PRIORITY_HIGH)
val firebaseDatabase = FirebaseDatabase.getInstance()
val databaseReference = firebaseDatabase.reference
CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
if
(isChecked) {
when (buttonView.id) {
R.id.checkBox -> {
databaseReference.child(
"check"
).push().setValue(
"c"
)
}
R.id.checkBox2 -> {
databaseReference.child(
"check"
).push().setValue(
"d"
)
}
R.id.checkBox3 -> {
databaseReference.child(
"check"
).push().setValue(
"e"
)
}
}
}
else
{
when (buttonView.id) {
R.id.checkBox -> {
databaseReference.child(
"check"
).push().setValue(
""
)
}
R.id.checkBox2 -> {
databaseReference.child(
"check"
).push().setValue(
""
)
}
R.id.checkBox3 -> {
databaseReference.child(
"check"
).push().setValue(
""
)
}
}
}
notify(NOTIFICATION_ID, build.build())
}
}
}