-
-
Save garg-lucifer/02833f8292bd625f1df5f002e6caa2e0 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
class AlarmReceiver : BroadcastReceiver() { | |
private var notificationManager: NotificationManagerCompat? = null | |
override fun onReceive(p0: Context?, p1: Intent?) { | |
val taskInfo = p1?.getSerializableExtra("task_info") as? TaskInfo | |
// tapResultIntent gets executed when user taps the notification | |
val tapResultIntent = Intent(p0, MainActivity::class.java) | |
tapResultIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP | |
val pendingIntent: PendingIntent = getActivity( p0,0,tapResultIntent,FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE) | |
val notification = p0?.let { | |
NotificationCompat.Builder(it, "to_do_list") | |
.setContentTitle("Task Reminder") | |
.setContentText(taskInfo?.description) | |
.setSmallIcon(R.mipmap.ic_launcher) | |
.setAutoCancel(true) | |
.setPriority(NotificationCompat.PRIORITY_HIGH) | |
.setContentIntent(pendingIntent) | |
.build() | |
} | |
notificationManager = p0?.let { NotificationManagerCompat.from(it) } | |
notification?.let { taskInfo?.let { it1 -> notificationManager?.notify(it1.id, it) } } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment