From the course: Concurrent Programming with Android: Threads, Workers, and Kotlin Coroutines

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Send intents from a foreground notification

Send intents from a foreground notification

- [Instructor] When you display a notification to put a service into the foreground, you can add action buttons to the notification. Each button has a label and when the user touches or clicks the button, it sends an intent back to the service that launched the notification. It's up to the service to interpret the intent and take whatever action is requested. First, I'll add code to create a pending intent. Each intent will need an action, a string that's best represented as a constant. I'll place those constants in MyService class. I'll put these up at the top of the class and the first one will be called NOTIFICATION_ACTION_PLAY, The actual string can be anything you like. I'll just call it action_play, and the second will be NOTIFICATION_ACTION_STOP. Next, I'll create a new function and I'll place it down here at the bottom. This is going to be named getPendingIntent. This is a reusable function that will create an…

Contents