Notification (API14) 创建过程

(1)创建一个NotificationManager对象 可通过Context的getSystemService()方法获取到,传入Context.NOTIFICATION_SERVICE.

NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

(2)创建Notification对象。高于API Level 11,低于API Level 16 (Android 4.1.2)版本的系统中,可使用Notification.Builder来构造函数。但要使用getNotification()来使notification实现。前面版本在notification中设置的Flags,icon等属性都已经无效,要在builder里面设置。

notification = new Notification.Builder(context).setAutoCancel(true)  
                .setContentTitle("qq正在运行").setContentText("qq,让交流更多方便")  
                .setContentIntent(mPendingIntent)  
                .setSmallIcon(R.drawable.ic_launcher)  
                .setWhen(System.currentTimeMillis()).build();  

(3)调用NotificationManager的notify()方法让通知显示
manager.notify(id , 创建的Notification对象);
效果
这里写图片描述
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值