Introduction ( download address )
Ba-NotifyEarphone is a plug-in for customizing the notification style (earphone power), if you have other customization needs, please contact the author.
- Headphone power notification, support for custom colors, pictures, etc.
- Support for listening to click events
- Support judging whether to open the notification permission
- Support jumping to the notification setting interface
- Support for clearing notification messages
- Support resident notification mode (parameter setting is enough, autoCancel and ongoing)
Universal application message notification plugin Ba-Notify ( documentation )
screenshot display
Instructions
script
Introduce components in
const notify = uni.requireNativePlugin('Ba-NotifyEarphone')
script
Called in (example reference, you can modify it according to your own business and calling method)
methods: {
showNotify() {
let content = 'content';
notify.show({
'ticker': 'Ticker',
'autoCancel': false,
'ongoing': true,
'text1': '60%',
'text1Color': '#ff0000',
},
(res) => {
console.log(res)
});
},
isNotifyEnabled() {
//是否打开通知权限
notify.isNotifyEnabled(
(res) => {
console.log(res)
uni.showToast({
title: 'isNotifyEnabled:' + res.isNotifyEnabled ? true : false,
icon: "none"
})
});
},
goSetNotify() {
//跳转到通知设置界面
notify.goSetNotify();
},
clear() {
//清空某类型消息
notify.clear({
//'channelID': '0',
//'channelName': 'channel_0',
//'ID': 1,
});
},
}
Notify click event listener
Set the listener in the onLaunch event of the application lifecycle app.vue:
onLaunch: function() {
this.checkArguments();
// 重点是以下: 一定要监听后台恢复 !一定要
plus.globalEvent.addEventListener('newintent', (e) => {
this.checkArguments(); // 检测启动参数
});
},
onShow: function() {
},
onHide: function() {
},
methods: {
checkArguments() {
var args = plus.runtime.arguments;
if (args) {
let args1 = JSON.parse(args);
if (args1.BaNotifyEarphone) {
//判断是否为通知传来的消息
//这里写你的处理逻辑
console.log(JSON.stringify(args1))
}
}
},
}
Click event parameters
attribute name | illustrate |
---|---|
ChannelID | The channel ID of the notification you set |
ChannelName | The channel name of the notification you set |
ID | The ID of the notification you set |
extend | Additional parameters |
Example:
{
"extend":"","ChannelID":"98","ID":"998","BaNotifyEarphone":"true","ChannelName":"BaNotifyEarphone"}
UI icon set
Note: After the change, the base needs to be remade to take effect. It is recommended to configure it in advance.
- Small notification icon : The default notification icon is the Android icon. If you need to use your own, add "ba_notify_earphone_icon.png" in the "nativeplugins\Ba-NotifyEarphone\android\res\mipmap-xxhdpi" directory of the project (create it if you don't have it) Picture files are fine.
- Headphone icon : comes with a default icon, if you need to use your own, add a picture file in the "nativeplugins\Ba-NotifyEarphone\android\res\drawable" directory of the project (if not, create a new one), that is, "ic_notify_earphone1.png" , "ic_notify_earphone2.png", "ic_notify_earphone3.png".
api list
method name | illustrate |
---|---|
show | show notification |
isNotifyEnabled | Whether notification permission is turned on |
goSetNotify | Jump to the notification settings interface to set notifications |
clear | Clear a certain type of message |
Method show call parameters
attribute name | type | Defaults | illustrate |
---|---|---|---|
channelID | String | “98” | ChannelId |
channelName | String | “BaNotifyEarphone” | channel name |
ID | Number | 998 | notification id |
isSound | Boolean | true | sound |
isVibrate | Boolean | true | shock |
isLights | Boolean | true | flash |
ticker | String | ‘’ | Tooltips in the top status bar |
autoCancel | Boolean | true | Click the notification, it will disappear automatically, the default is true |
ongoing | Boolean | false | The notification is continuously displayed, and the side sliding cannot be deleted. The default is false |
text1 | String | ‘100%’ | Power 1 |
text2 | String | ‘100%’ | Power 2 |
text3 | String | ‘100%’ | Power 3 |
text1Color | String | '#68A548' | text1 color value, hexadecimal |
text2Color | String | '#68A548' | text2 color value, hexadecimal |
text3Color | String | '#68A548' | text3 color value, hexadecimal |
Method clear call parameters
attribute name | type | Defaults | illustrate |
---|---|---|---|
channelID | String | “98” | ChannelId |
channelName | String | “BaNotifyEarphone” | channel name |
ID | Number | 998 | notification id |
The method isNotifyEnabled return parameter
attribute name | type | illustrate |
---|---|---|
isNotifyEnabled | Boolean | Whether notification permission is turned on |
Series plug-in
Image selection plugin Ba-MediaPicker ( documentation )
Image editing plugin Ba-ImageEditor ( documentation )
File picker plugin Ba-FilePicker ( documentation )
应用消息通知插件(多种样式,新增支持常驻通知模式) Ba-Notify(文档)
自定义通知(耳机电量)插件 Ba-NotifyEarphone(文档)
应用未读角标插件 Ba-Shortcut-Badge (文档)
扫码原生插件(毫秒级、支持多码)Ba-Scanner-G(文档)
扫码原生插件 - 新(可任意自定义界面版本;支持连续扫码;支持设置扫码格式)Ba-Scanner(文档)
动态修改状态栏、导航栏背景色、字体颜色插件 Ba-AppBar(文档)
安卓保活插件(采用多种主流技术) Ba-KeepAlive(文档)
安卓快捷方式(桌面长按app图标) Ba-Shortcut(文档)
自定义图片水印(任意位置) Ba-Watermark(文档)
最接近微信的图片压缩插件 Ba-ImageCompressor(文档)
视频压缩、视频剪辑插件 Ba-VideoCompressor(文档)
动态切换应用图标、名称(如新年、国庆等) Ba-ChangeIcon(文档)
原生Toast弹窗提示(穿透所有界面、穿透原生;自定义颜色、图标 ) Ba-Toast(文档)
websocket原生服务(自动重连、心跳检测) Ba-Websocket(文档)
智能安装(自动升级) Ba-SmartUpgrade(文档)
监听通知栏消息(支持白名单、黑名单、过滤) Ba-NotifyListener(文档)
全局置灰、哀悼置灰(可动态、同时支持nvue、vue) Ba-Gray(文档)
获取设备唯一标识(OAID、AAID、IMEI等) Ba-IdCode(文档)
实时定位(系统、后台运行、支持息屏)插件 Ba-Location(文档)
实时定位(高德、后台运行、支持息屏、坐标转换、距离计算) Ba-LocationAMap(文档)
窗口小工具、桌面小部件、微件 Ba-AppWidget(文档)
窗口小工具、桌面小部件、微件(日历、时间) Ba-AwCalendarS(文档)
悬浮窗(在其他应用上层显示) Ba-FloatWindow(文档)
悬浮窗(应用内、无需授权) Ba-FloatWindow2(文档)
Floating window (floating ball, dynamic menu, display on top of other applications) Ba-FloatBall ( documentation )
Added to "Open with other apps" for file delivery, sharing, etc. Ba-ShareReceive ( documentation )
Get Map Data (Geocode, Geocoding, Anti-Geocoding) Ba-AMapData ( documentation )