Android创建使用默认布局的通知
2015-11-24 19:50
966 查看
创建一个使用默认布局的通知:
[code]NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher,"this is ticker text",System.currentTimeMillis()); // 第一个参数用于指定通知图标,第二个参数用于指定通知到来时闪一下显示的文字,第三个显示通知到来的时间 Intent intent = new Intent(this,NotificationActivity.class); PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT); // 设置通知点击响应 notification.setLatestEventInfo(this,"this is content title","this is content text",pi); // 用于指定通知布局显示内容 Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg")); notification.sound = sound; // 通知到来时铃声提醒 /** * 需要震动权限 */ long[] vibrates = {0,1000,1000,1000}; // 0,2,4...表示静止时长,1,3,5...表示震动时长 notification.vibrate = vibrates; // 设置震动提醒(这个数组的意思是,来了同时马上震动1秒,静止一秒,再震动一秒) /** * 用于实现有未读通知时LED灯闪烁 */ notification.ledARGB = Color.GREEN; // 一般有红绿蓝可选 notification.ledOnMS = 1000; // 指定LED灯亮起的时长,以毫秒为单位 notification.ledOffMS = 1000; // 指定LED灯暗去的时长,以毫秒为单位 notification.flags = Notification.FLAG_SHOW_LIGHTS; // flags用于指定通知一些行为,其中就有显示LED灯这一项 manager.notify(1,notification); // 显示通知,每个通知的id(第一个参数)要唯一
相关文章推荐
- Github项目解析(二)-->将Android项目发布至JCenter代码库
- Android照片墙应用实现 图片多也可以
- Android Studio的插件开发
- Android_改变状态栏颜色
- Android Log工具之Luffy
- Android启动过程
- Android ListView相关
- Android开发时如何用小米3进行真机调试
- Android中如何将Bitmap byte裸数据转换成Bitmap图片int数据
- Head First Android Development-笔记
- android:数据保存之SQLite
- Mac下android开发环境的搭建
- Android下拉/上拉刷新ListView之Android-PullToRefresh
- Android 总结:进阶之路(资源与方法)
- android raw与assets区别
- Android 5.0 避免重复启动KeyguardService导致系统报错
- Android SwipeRefreshLayout:谷歌官方SDK包中的下拉刷新
- Android ListView实战
- 学习日记--android显示动态GIF文件代码
- java、android拼音,中文姓名排序