Android点击通知栏 ,移除通知

创建一个Android通知,通过设置`autoCancel`为true,实现点击通知栏时自动移除通知。示例代码包括构建通知、远程视图以及适应Android 6.0以上系统的配置。
摘要由CSDN通过智能技术生成

通过点击系统通知栏移除 通知只需要一个方法
Notification notification = new Notification();
notification.setAutoCancel(true);

下面是整个系统弹窗的方法已做了6.0设配
/**
* 头部系统消息提示
* 状态栏提示消息
*/
private void setNotificationDemoForAndroidO(int progress, String content, Context context) {
//ID
String id = “testNotification”;
//名称
String name = “notification”;

    NotificationManager notificationManager = (NotificationManager) context.getSystemService
            (NOTIFICATION_SERVICE);
    Notification.Builder mBuilder = new Notification.Builder(context);
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_notification);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(id, name, NotificationManager
                .IMPORTANCE_DEFAULT);//FLAG_AUTO_CANCEL
        mBuilder.setChannelId(id);
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值