安卓Notification通知栏全解

全栈工程师开发手册 (作者:栾鹏)
安卓教程全解

安卓通知栏是提醒用户信息有效手段,也是通过用户的行为触发事件服务的方式。

Notification允许在当前应用程序不活动或不可见时向用户发送信号。

创建通知栏有使用Notification直接创建何使用Notification.Builder创建两种方法

1、使用Notification直接创建通知栏

private Notification simpleNotification() {
	    //选择一个drawable来作为状态栏图标显示
	    int icon = R.drawable.icon;
	    //当启动通知时在状态栏中显示的文本
	    String tickerText = "通知显示文本";
	    //展开的状态栏按时间顺序排序通知
	    long when = System.currentTimeMillis();  //指定时间戳
	    Notification notification = new Notification(icon, tickerText, when);
	    //notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;   //将默认的声音和神东赋值给notification
	    Uri ringUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);  //获取系统某音频文件的uri
	    notification.sound = ringUri;   //设置notification的提示声音
	    notification.flags=notification.flags|Notification.FLAG_ONGOING_EVENT;  //设置为持续的notification
	    //notification.flags=notification.flags|Notification.FLAG_INSISTENT;  //建议不要使用,设置为连续的notification,会一直重复音频、震动和闪灯设置,直到被取消.
	    return notification;
	  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

腾讯AI架构师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值