android app crashes on launch when i try to declare an intent in kotlin-ThrowExceptions

Exception or error:

please help

val snoozeIntent = Intent(this, SnoozeReceiver::class.java).apply {
        action = "ACTION_SNOOZE"
        putExtra("EXTRA_NOTIFICATION_ID", 0)
    }

i’m trying to follow the documentation here:
https://developer.android.com/training/notify-user/build-notification#Actions

my broadcast class:

class SnoozeReceiver: BroadcastReceiver() {
    private val REQUEST_CODE = 0

    override fun onReceive(context: Context, intent: Intent) {
        val triggerTime = SystemClock.elapsedRealtime() + DateUtils.MINUTE_IN_MILLIS

        val notifyIntent = Intent(context, AlarmReceiver::class.java)
        val notifyPendingIntent = PendingIntent.getBroadcast(
            context,
            REQUEST_CODE,
            notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT
        )
        val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        AlarmManagerCompat.setExactAndAllowWhileIdle(
            alarmManager,
            AlarmManager.ELAPSED_REALTIME_WAKEUP,
            triggerTime,
            notifyPendingIntent
        )

        val notificationManager = ContextCompat.getSystemService(
            context,
            NotificationManager::class.java
        ) as NotificationManager
        notificationManager.cancelAll()
    }

}

Android manifest :

<receiver
                android:name=".receiver.SnoozeReceiver"
                android:enabled="true"
                android:exported="false">
            <intent-filter>
                <action android:name="ACTION_SNOOZE"/>
            </intent-filter>
        </receiver>
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *