转载:监听通知栏内容,获取通知栏消息,安卓原生SDK扩展
<template>
<view>
{{msg}}
<view>
<view v-for="(item, index) in list" :key="index">
<text>监听到内容:{{item.content}}</text><br><text>监听到标题:{{item.title}}</text>
<br /><hr />
</view>
</view>
<button type="default" @click="init">初始化</button>
<button type="default" @click="test">是否开启获取通知权限</button>
<button type="default" @click="set">跳转到设置界面</button>
<button type="default" @click="start">开始监听</button>
<button type="default" @click="clear">清空列表记录</button>
<button type="default" @click="cancelAll">清空所有通知栏消息</button>
<button type="default" @click="isIgnoringBatteryOptimizations">是否设置白名单</button>
<button type="default" @click="requestIgnoreBatteryOptimizations">去设置白名单</button>
</view>
</template>
<script>
const NoticeBarModule = uni.requireNativePlugin('lu-NoticeBarModule');
export default {
data() {
return {
msg: '收到的通知内容会展示在这里',
list: []
}
},
onLoad() {},
methods: {
init() {
NoticeBarModule.init();
},
clear() {
this.list = [];
},
test() {
let res = NoticeBarModule.readNotificationBar();
if (res) {
uni.showToast({
title: '开启',
icon: 'none'
});
} else {
uni.showToast({
title: '未开启',
icon: 'none'
});
}
},
set() {
NoticeBarModule.toSetting();
},
cancelAll() {
NoticeBarModule.cancelAll();
},
start() {
let _this = this;
NoticeBarModule.getNotification(e => {
_this.list.push(e);
console.log(JSON.stringify(e));
uni.showToast({
title: JSON.stringify(e),
icon: 'none'
});
});
},
isIgnoringBatteryOptimizations() {
let res = NoticeBarModule.isIgnoringBatteryOptimizations();
if (res) {
uni.showToast({
title: '已开启白名单',
icon: 'none'
});
} else {
uni.showToast({
title: '未开启白名单',
icon: 'none'
});
}
},
requestIgnoreBatteryOptimizations() {
NoticeBarModule.requestIgnoreBatteryOptimizations()
}
}
}
</script>
<style>
</style>
|