uniapp listen notification bar message plug-in (support whitelist, blacklist, filtering) Ba-NotifyListener

Introduction ( download address )

Ba-NotifyListener is a uniapp plug-in for real-time monitoring of notification bar messages. Support whitelist, blacklist; support monitoring message removal; support custom filter conditions (such as SMS verification code), etc.

  • Support listening to all notification bar messages (including id, ticker, title, content, time, etc.)
  • Support whitelist (applications that need to be monitored, other applications will not monitor after setting)
  • Support blacklist (apps that do not want to monitor, valid when no whitelist is set)
  • Support custom content filtering conditions (such as filtering SMS verification codes, filtering 4~8 digits by default)

Related plugins

Application message notification plug-in (multiple styles, new support for resident notification mode) Ba-Notify ( documentation )

Apply the unread badge plugin Ba-Shortcut-Badge ( documentation )

SMS monitoring (verification code) Ba-Sms ( documentation )

screenshot display

insert image description here

Instructions

scriptIntroduce components in

	const listener = uni.requireNativePlugin('Ba-NotifyListener');

scriptCalled in (example reference, you can modify it according to your own business and calling method)

	const listener = uni.requireNativePlugin('Ba-NotifyListener'); //本插件
	const notify = uni.requireNativePlugin('Ba-Notify'); //应用通知插件(https://ext.dcloud.net.cn/plugin?id=9231)
	export default {
    
    
		data() {
    
    
			return {
    
    
				whiteList: [ //白名单
					'com.ba.UniTemp',
					'com.tencent.mobileqq', //qq
					'com.tencent.mm', //微信
					'com.android.mms', //短信
					'com.android.incallui', //来电
				],
				blackList: [ //黑名单
					'com.ba.UniTemp',
				],
				msgList: []
			}
		},
		methods: {
    
    
			setListener(flag = 0) {
    
     //设置监听
				let params = {
    
    };
				if (flag == 1) {
    
    
					params = {
    
    
						whiteList: this.whiteList,
					    //regex: "(\\d{4,8})",正则表达式,默认为匹配4-8位的数字
					};
				} else if (flag == 2) {
    
    
					params = {
    
    
						blackList: this.blackList,
					    //regex: "(\\d{4,8})",正则表达式,默认为匹配4-8位的数字
					};
				}
				listener.setListener(params, res => {
    
    
					console.log(res);
					if (res.ok && res.data) {
    
    
						if (res.data.listenType == 1) {
    
    
							this.msgList.push('收到消息:');
							this.msgList.push(JSON.stringify(res.data));
							if (res.data.result)
								this.msgList.push("解析结果:" + res.data.result);

						}
						if (res.data.listenType == 2) {
    
    
							this.msgList.push('移除消息:');
							this.msgList.push(JSON.stringify(res.data));
						}
					}
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			isHasPermission() {
    
     //是否开启获取通知权限
				listener.isHasPermission(res => {
    
    
					console.log(res);
					uni.showToast({
    
    
						title: res.ok ? (res.data && res.data.isHasPermission ? '已开启' : '未开启') : res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			openPermission() {
    
     //跳转到通知权限设置界面(仅判断未打开时跳转)
				listener.openPermission(res => {
    
    
					let msg = res.msg;
					if (res.data && res.data.isHasPermission) {
    
    
						msg = res.data.isHasPermission ? "权限打开" : "权限关闭";
					}
					uni.showToast({
    
    
						title: msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			setPermission() {
    
     //跳转到通知权限设置界面(开不开都跳转)
				listener.setPermission(res => {
    
    
					console.log(res);
					let msg = res.msg;
					if (res.data && res.data.isHasPermission) {
    
    
						msg = res.data.isHasPermission ? "权限打开" : "权限关闭";
					}
					uni.showToast({
    
    
						title: msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			sendNotify() {
    
    //用于测试通知
				notify.show({
    
    
						channelID: '0',
						channelName: '普通通知',
						ID: 1,
						notifyType: 0,
						ticker: 'Ticker',
						title: 'title',
						content: "【某某应用】验证码:708563。尊敬的用户,您正在...,我们不会向您索要此验证码,切勿告知他人!",
						extend: "附加参数",
					},
					(res) => {
    
    
						console.log(res)
					});
			}
		}
	}		

api list

method name illustrate
setListener set monitor
isHasPermission Whether to enable the notification permission
openPermission Jump to the notification permission setting interface (jump only when it is not turned on)
setPermission Jump to the notification permission setting interface (jump if it is turned on or not)

setListener method parameters

set monitor

attribute name type required Defaults illustrate
whiteList Array false ‘’ whitelist
blackList Array false ‘’ blacklist
regex String false ‘’ Regular expression to filter SMS content, by default filter 4~8 digit verification code, such as '(\d{4,8})'

Parameters for listening to notifications

Judging that res.data has content (refer to usage method), listen to the received notification

attribute name type illustrate
listenType Number 1 Receive notification 2 Remove notification
packageName String Application package name
id Number notification id
postTime long time (milliseconds)
postTimeS String Time (yyyy-MM-dd HH:mm:ss format)
tickerText String Notify the ticker, the prompt message in the top status bar
title String notification title
content String notification content
result String The notification content is analyzed according to the filtering rules, such as SMS verification code
isOngoing Boolean Whether the notification continues to be displayed, and cannot be deleted by sliding
isClearable Boolean Click on the notification, whether it will disappear automatically

isHasPermission, openPermission, setPermission method return parameters

Judging that res.data has content (refer to usage method)

attribute name type illustrate
isHasPermission Boolean Whether to enable the notification permission

Series plug-in

Image selection plugin Ba-MediaPicker ( documentation )

Image editing plugin Ba-ImageEditor ( documentation )

File picker plugin Ba-FilePicker ( documentation )

Application message notification plug-in (multiple styles, new support for resident notification mode) Ba-Notify ( documentation )

Apply the unread badge plugin Ba-Shortcut-Badge ( documentation )

Applying the Ba-Autoboot plugin ( documentation )

Scan code native plug-in (millisecond level, support multi-code) Ba-Scanner-G ( documentation )

Native plug-in for scanning code - new (can customize the interface version arbitrarily; support continuous scanning code; support setting scanning code format) Ba-Scanner ( documentation )

Dynamically modify the status bar, navigation bar background color, font color plug-in Ba-AppBar ( documentation )

Native sqlite local database management Ba-Sqlite ( documentation )

Android keep-alive plug-in (using a variety of mainstream technologies) Ba-KeepAlive ( documentation )

Android shortcut (desktop long press app icon) Ba-Shortcut ( documentation )

Custom image watermark (anywhere) Ba-Watermark ( documentation )

The closest image compression plug-in to WeChat is Ba-ImageCompressor ( documentation )

Video compression, video editing plug-in Ba-VideoCompressor ( documentation )

Dynamically switch application icons and names (such as New Year, National Day, etc.) Ba-ChangeIcon ( documentation )

Native Toast pop-up prompt (through all interfaces, through native; custom colors, icons) Ba-Toast ( documentation )

Image graffiti, brush Ba-ImagePaint ( documentation )

pdf reading (gesture zoom, display page number) Ba-Pdf ( documentation )

Sound reminder, vibration reminder, voice broadcast Ba-Beep ( documentation )

Websocket native service (automatic reconnection, heartbeat detection) Ba-Websocket ( documentation )

SMS monitoring (verification code) Ba-Sms ( documentation )

Smart Install (Automatic Upgrade) Ba-SmartUpgrade ( documentation )

Monitor system broadcast, custom broadcast Ba-Broadcast ( documentation )

Listen to notification bar messages (support whitelist, blacklist, filter) Ba-NotifyListener ( documentation )

Global graying, mourning graying (dynamic, support nvue, vue at the same time) Ba-Gray ( documentation )

Get Device Unique Identifier (OAID, AAID, IMEI, etc.) Ba-IdCode ( documentation )

Guess you like

Origin blog.csdn.net/u013164293/article/details/128137134