코틀린을 공부중인 학생입니다
노피티케이션으로 팝업창이 뜰때 체크박스의 값이 파이어베이스로 넘어가게 설계하고 싶은데
잘 안됩니다... 아래가 코드의 일부입니다
어떻게 수정을 해야 제가 원하는대로 코드를 짤 수 있을까요?
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())
}
}
}
우선 앱 자체는 알람을 울려주는 앱이고 알람이 울리긴하나 값이 넘어가진 않습니다...
요거는 혹시 몰라서 첨부하는 알람리시버 쪽 코딩 전문입니다...
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())
}
}
}