How to read notifications for API Level < 18 (NotificationListenerService requires API >= 18)

StackOverflow https://stackoverflow.com/questions/23466851

  •  15-07-2023
  •  | 
  •  

Question

I am trying read all incoming notifications (here is the code example). When I extend NotificationListenerService, I get the following message:

Call requires API level 18 (current min is 9): new android.service.notification.NotificationListenerService

I want to add this functionality to my app but do not want to alienate users who are below API level 18. Is there a workaround to this problem?

Était-ce utile?

La solution

Yes you can do this by using AccessibilityService. Where an accessibility service runs in the background and receives callbacks by the system when AccessibilityEvents are fired. Such events denote some state transition in the user interface, for example, the focus has changed, a button has been clicked, etc. Such a service can optionally request the capability for querying the content of the active window.

Read my bolog post Capture Toast or Notification using Accessibility Service for code example.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top