标签:
首先需要一个NotificationManager来对通知进行管理,可以调用Context的getSystemService()方法获取到。getSystemService()接收的参数为Context.NOTIFICATION_SERVICE。
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
创建一个Notification对象这个对象用于存储通知所需的各种信息
第三个参数用于指定通知被创建的时间,以毫秒为单位
Notification notification = new Notification(R.drawable.icon,"This is ticker text"</span>,System.currentTimeMillis());
调用Notification的setLatestEventInfo()方法可以给通知设置一个标准布局
notification.setLatesEventInfo(context,"This is content title","This is content text",pendingIntent);
调用NotificationManager的notify()方法可以让通知显示出来
manager.notify(1,notification);
NotificationManager的cancel()方法可以取消通知
sound属性可以在通知里播放一段音频
Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg"));
notification.sound = soundUri;
vibrate属性可以让手机进行振动
long[] vibrate = {0,1000,1000,1000};
notification.vibrate = vibrates;
控制手机的LED灯显示
notification.ledARGB = Color.GREEN;
notification.ledOnMS = 1000;
notification.ledOffMS = 1000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
标签:
原文地址:http://blog.csdn.net/linux_gtx/article/details/51371695