How to cancel Notification scheduled using Alarm manager when app is not open?

Viewed 14

I am using Alarm manager to show Local notification reminder here is my code to schedule a notification.

    val intent = Intent(context?.applicationContext,ReminderNotification::class.java)
    intent.putExtra(titleExtra,getTitle())
    intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP

    val pendingIntent = PendingIntent.getBroadcast(
        context?.applicationContext,
        uniqueId,
        intent,
        PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
    )

    mAlarmManager = context?.getSystemService(Context.ALARM_SERVICE) as AlarmManager
    val time = getTime(nextServiceDate)
    //repeat every day
    mAlarmManager?.setRepeating(
        AlarmManager.RTC_WAKEUP,
        time,
        1000 * 60 * 60 * 24,
        pendingIntent
    )//1000 * 60 * 60 * 24

I need to cancel alarm after 7 days of its scheduling. My issue is that how to cancel alarm if user not open application.

Thanks in Advance!!

0 Answers
Related