-
-
Save garg-lucifer/2e1d485efed5550963ed386bb85d2a4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setAlarm(taskInfo: TaskInfo) { | |
// creating alarmManager instance | |
val alarmManager = activity?.getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
// adding intent and pending intent to go to AlarmReceiver Class in future | |
val intent = Intent(requireContext(), AlarmReceiver::class.java) | |
intent.putExtra("task_info", taskInfo) | |
val pendingIntent = PendingIntent.getBroadcast(requireContext(), taskInfo.id, intent, PendingIntent.FLAG_IMMUTABLE) | |
// when using setAlarmClock() it displays a notification until alarm rings and when pressed it takes us to mainActivity | |
val mainActivityIntent = Intent(requireContext(), MainActivity::class.java) | |
val basicPendingIntent = PendingIntent.getActivity(requireContext(), taskInfo.id, mainActivityIntent, PendingIntent.FLAG_IMMUTABLE) | |
// creating clockInfo instance | |
val clockInfo = AlarmManager.AlarmClockInfo(taskInfo.date.time, basicPendingIntent) | |
// setting the alarm | |
alarmManager.setAlarmClock(clockInfo, pendingIntent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment