您当前的位置: 首页 >  宴西笔记

Auto.js 设置通知栏

宴西笔记 发布时间:2022-03-13 21:25:01 ,浏览量:3

在这里插入图片描述

"ui";
ui.layout(
    
        
        
    
);
ui.notify.on("click", () => {
    var manager = context.getSystemService(android.app.Service.NOTIFICATION_SERVICE);
    var notification;
    if (device.sdkInt >= 26) {
        var channel = new android.app.NotificationChannel("channel_id", "channel_name", android.app.NotificationManager.IMPORTANCE_DEFAULT);
        channel.enableLights(true);
        channel.setLightColor(0xff0000);
        channel.setShowBadge(false);
        manager.createNotificationChannel(channel);
        notification = new android.app.Notification.Builder(context, "channel_id")
            .setContentTitle("通知栏标题")
            .setContentText("这是消息的内容")
            .setWhen(new Date().getTime())
            .setSmallIcon(android.R.drawable.ic_delete)
            .setTicker("这是状态栏显示的内容")
            .build();
    } else {
        notification = new android.app.Notification.Builder(context)
            .setContentTitle("通知栏标题")
            .setContentText("这是消息的内容")
            .setWhen(new Date().getTime())
            .setSmallIcon(org.autojs.autojs.R.drawable.autojs_material)
            .setTicker("这是状态栏显示的内容")
            .build();
    }
    manager.notify(1, notification);
});
ui.cancel.on("click", () => {
    var manager = context.getSystemService(android.app.Service.NOTIFICATION_SERVICE);
    manager.cancelAll();
    // manager.cancel(1);
});
关注
打赏
1688896170
查看更多评论

宴西笔记

暂无认证

  • 3浏览

    0关注

    82博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0455s