Filtering Foreground Notifications
With that sharp corner filed down a bit, we turn to another imperfection in PhotoGallery. Your notifications work great, but they are sent even when the user already has the application open.
You can fix this problem with broadcast intents, too. But they will work in a completely different way.
Sending broadcast intents
This is the easiest part of the solution: sending your own broadcast intent. To send a broadcast intent, just create an intent and pass it in to sendBroadcast(Intent). In this case, you will want it to broadcast an action you define, so define an action constant as well. Add the following bits of code to PollService.
Listing 30.5 Sending a broadcast intent (PollService.java)
public class PollService ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access