总览

requestListeningNotifications(options?): Promise<NotificationListenerService>

请求监听通知,使本应用获取通知监听服务的权限。返回通知监听服务NotificationListenerService的Promise对象。

示例

"nodejs";
const notification = require('notification');
 
async function main() {
    const notificationListenerService = await notification.requestListeningNotifications({
        toast: true,
    });
    console.log('listening notifications...');
    notificationListenerService.on("notification", n => {
        console.log("收到通知");
        console.log(`标题: ${n.getTitle()}, 文本: ${n.getText()}, 包名: ${n.getPackageName()}`);
    });
 
    $autojs.keepRunning();
}
main();

参数

名称类型默认值描述
options?RequestListeningNotificationsOptionstbd请求监听通知的选项,比如显示给用户的Toast信息

返回值

Promise<NotificationListenerService>


2023-02-15