Is there a way to let a <NotificationListenerServi...
# android
r
Is there a way to let a NotificationListenerService block notifications that contain a full screen Intent?
stackoverflow 3
😶 5
For instance an incoming phone call will post it's notification to the NotificationManager (with notifiy() ), and onNotificationPosted() in all connected listeners will also get called. But then calling cancelNotification() does not cancel the launching of the full screen intent by the NotificationManager. Meaning the incoming phone call UI is still shown.
Secondly you can not call cancel() on the pending intent since only the original app that created the pending intent has the security permission to do so.
So it seems onNotificationPosted() is called after the notification manager launches the fullscreen intent. When the device is unlocked this does not happen since the System-UI then shows a 'heads up' notification instead. Which will be hidden by the notification listener if you call cancelNotification()
Any suggestions for a solution?
I tried turning Do Not Disturb on for 30 seconds right after onNotificationPosted() is called, but this is quite flaky.
Searching for a better solution, I welcome any ideas 💡
a
What kind of product feature for your app are you trying to implement by doing this?
r
mainly blocking of VOIP calls like WhatsApp calling, for SIM based calls you have the CallScreeningService API (From Android 10 and up) but you can not block VOIP calls with that
but this also applies to any app that posts notifications with a full screen intent, like the samsung calender app does by default
Any idea @Adam Powell ?
a
no, and frankly anything you find here is likely to run into troubles of forward compatibility on future platform versions. The behavior you're trying to achieve is indistinguishable to the system from a DoS on other apps, i.e. malware behavior. The capabilities of notification listeners are primarily targeted at use cases of accessing/manipulating your phone from another device, not suppressing behavior on the phone. Anything you try to do here that isn't relevant for that target use case probably is possible only by accident, and may be "fixed" in a future version of Android as a security/privacy measure.
(Not to mention how Play Store policies might perceive it.)
l
Doesn't DoNotDisturb mode already disables auto-launch of fullscreen intents, besides alarm clock ones?
r
it does indeed but Im searching for a way to toggle it before the fullscreen intent is launched, i.e. some sort of callback. On SO there are a lot of topics abouts blocking of Skype/WhatsApp calls but no real clean solution other then audiofocus listeners
l
Then, why not simply use DND? You could still add a custom alerting for notifications that doesn't trigger a full screen intent, and you can probably find a way to make it work while in DND, by using media or alarm stream for example.
r
thnx, but the app is event based with complex logic and the DND API is very limited (can only block 'starred' or all contacts) so unfortunately that's not a good solution.
In response to @Adam Powell; If Google doesn't want developers to get 'creative' and use other API's maybe it's time to fix and expand the CallScreeningService API? In Android 12 DP3 the two year old critical bug that does not post blocked call notifications is still present (!). And voip support is fully missing from the API (self managed PhoneAccounts would be a start). This while amidst a global pandemic that forces billions of android users to work from home, often completely relying on voip calls/apps. So the ability to screen/block this communication is more relevant than ever.
☝️ 1