【notification】Android 中创建状态栏通知

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(android.R.drawable.btn_default, "新的通知", System.currentTimeMillis());     // 通过构造函数设定通知的图标与标题
Intent intentNoti = new Intent(Intent.ACTION_VIEW);    // 可以使用其他的意图,以实现希望的功能
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intentNoti, 0);
notification.setLatestEventInfo(getApplicationContext(), "通知的标题", "通知的内容", contentIntent);    // 设定通知的标题与内容,超出一行的部分将被省略
notificationManager.notify(notificationID, notification);   // 生成 ID 为 notificationID 的通知。若该 ID 已存在,则更新已有通知的内容

 

说明:NotificationManager 可以通过 getSystemService(NOTIFICATION_SERVICE) 方法取得。它本身还有一些其他的便利方法:cancel(int id)删除指定 id 的通知。cancelAll()删除本应用程序发出的所有通知。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值