Notification在Android中的应用

本文详细介绍了在Android中创建Notification的过程,包括获取Notification服务、创建Notification对象、设置通知信息和触发事件等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// A、首先需要获取系统Notification服务
                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
             // B、创建Notification,参数为别为图标、提示标题、提示时间
                Notification notification = new Notification(R.drawable.icon,"即兴提示aa!",System.currentTimeMillis()); //System.currentTimeMillis()
             // C、创建意图Intent并转化为非即时意图,这样就可以在任何不确定时间被执行
                Intent intents = new Intent(FirstActivity.this,TestActivity.class); 
                PendingIntent contentIntent = PendingIntent.getActivity(FirstActivity.this,0,intents,0);
             // D、设置Notification标题、内容和触发事件
                notification.setLatestEventInfo(FirstActivity.this, "ATAAW.COM", "即兴时代!", contentIntent);
                notification.flags|=Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
             // E、开启提示
                notificationManager.notify(1,notification);
//             // F、取消提示
//                notificationManager.cancel(1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值