79672201

Date: 2025-06-19 14:18:21
Score: 2.5
Natty:
Report link

I will ask here so as not to open a new topic. The question has to do with NotificationListenerService. I was making an "app" for myself, that is, a service that intercepts notifications, and then when it detects a Spotify ad (package name com.spotify.music, notification title—whatever, notification text—Advertisement), silences the phone, and then restores the sound when the ad ends. Later, I decided that I actually like their ads for the premium account, and I added a switch to the MainActivity where the muting of ads for the Spotify premium account (package name com.spotify.music, notification title—Spotify, notification text—Advertisement) is turned on or off with an additional boolean variable stored in the shared preferences.

What happened is that the service completely ignores that later added variable, so it still silences the phone when any advertisement appears. Then I wasted half a day trying to find why the updated service didn't do what it should, until I completely uninstalled the app, then reinstalled it, and voila—only then did the service start doing what it should—mute the phone when an ad appears, but not for Spotify Premium ads. It was as if Android copied the original version of the service somewhere, and then regardless of what changes in subsequent versions, it used that first version.

The question is, is that the expected behavior of NotificationListenerService?

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: HenryC