Created
December 13, 2019 08:02
-
-
Save PatilShreyas/0d8472b5dee7dd5d2ba0e7714f82c8f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 scheduleAlarm( | |
| scheduledTimeString: String?, | |
| title: String?, | |
| message: String? | |
| ) { | |
| val alarmMgr = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
| val alarmIntent = | |
| Intent(applicationContext, NotificationBroadcastReceiver::class.java).let { intent -> | |
| intent.putExtra(NOTIFICATION_TITLE, title) | |
| intent.putExtra(NOTIFICATION_MESSAGE, message) | |
| PendingIntent.getBroadcast(applicationContext, 0, intent, 0) | |
| } | |
| // Parse Schedule time | |
| val scheduledTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()) | |
| .parse(scheduledTimeString!!) | |
| scheduledTime?.let { | |
| // With set(), it'll set non repeating one time alarm. | |
| alarmMgr.set( | |
| AlarmManager.RTC_WAKEUP, | |
| it.time, | |
| alarmIntent | |
| ) | |
| } | |
| } | |
| private fun showNotification(title: String, message: String) { | |
| NotificationUtil(applicationContext).showNotification(title, message) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment