Use of Android notification listener service

Use of Android notification listener service

brief introduction

At present, many third-party security apps have message management function or message box function, which can manage some useless messages in the filtering system and make the message bar cleaner. In fact, the implementation of this function is to use the notification permission provided in Android. Notification listener service is added after Android 4.3, which means that when the app you develop has this permission, you can listen to the changes of notifications in the current system. After Android 4.4, you can also expand to obtain notification details. Let's take a look at the specific use of notificationlistenerservice.

use

Create a new service class that inherits notificationlistenerservice and implements two important methods:

This service class is declared in androidmanifest.xml, and bind must be declared_ NOTIFICATION_ LISTENER_ Service license and intent filter

Android.service.notification.notificationlistenerservice, and the label label we see in the notification permission list in the system settings:

OK, it's so simple that you can complete the function of APP monitoring system notification bar. Next, let's take a look at the notificationlistenerservice class, which also provides some important methods:

There are also two important rewriting methods mentioned above:

These two important callback methods. Their parameter statusbarnotification object is the details of the current trigger change notification. Let's take a look at the use of statusbarnotification:

For the notification object returned by getnotification(), you can also see other relevant information of the notification in detail, such as:

Jump to the notification usage right page in system settings

Judge whether it has the right to use the notice

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>