Skip to content

Instantly share code, notes, and snippets.

@pedromassango
Created May 29, 2018 18:23
Show Gist options
  • Select an option

  • Save pedromassango/1461ec95663956192d2ff331732d3d9a to your computer and use it in GitHub Desktop.

Select an option

Save pedromassango/1461ec95663956192d2ff331732d3d9a to your computer and use it in GitHub Desktop.
/**
* Created by Pedro Massango on 5/28/18.
*/
class AlarmBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// Create the notification to be shown
val mBuilder = NotificationCompat.Builder(context!!, "my_app")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Alarm Manager")
.setContentText("Hora de tomar seus comprimidos.")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Get the Notification manager service
val am = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// Generate an Id for each notification
val id = System.currentTimeMillis()/1000
// Show a notification
am.notify(id.toInt(), mBuilder.build())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment