关于创建notification
2016-04-25 14:07
309 查看
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(this,NatificationActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
<pre name="code" class="java"> /*** 低于API Level 11版本,也就是Android 2.3.3以下的系统中,* setLatestEventInfo()函数是唯一的实现方法。*/// Notification notification = new Notification(R.mipmap.ic_launcher, "This is ticker text", System.currentTimeMillis());// Intent intent = new Intent(this,MainActivity.class);// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);// notification.setLatestEventInfo(this, title, message, pendingIntent);// manager.notify(id, notification);// notification.setLatestEventInfo(this, "This is content title","This is content text", null);
<pre name="code" class="java"> /*** 高于API Level 11,低于API Level 16 (Android 4.1.2)版本的系统中,* 可使用Notification.Builder来构造函数。* 但要使用getNotification()来使notification实现。*/Notification.Builder builder = new Notification.Builder(this).setAutoCancel(true).setTicker("This is ticker text").setContentTitle("This is content title").setContentText("This is content text").setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setWhen(System.currentTimeMillis())// .setVibrate(new long[]{0,500}).setDefaults(Notification.DEFAULT_ALL).setOngoing(false);Notification notification = builder.getNotification();// notification.ledARGB = Color.RED;// notification.ledOnMS = 500;// notification.ledOffMS = 500;// notification.flags = Notification.FLAG_SHOW_LIGHTS;
/*** 高于API Level 16的版本,* 就可以用Builder和build()函数来配套的方便使用notification了。*/// Notification notification = new Notification.Builder(this)// .setAutoCancel(true)// .setContentTitle("This is content title")// .setContentText("This is content text")//// .setContentIntent(pendingIntent)// .setSmallIcon(R.mipmap.ic_launcher)// .setWhen(System.currentTimeMillis())// .setOngoing(false)// .build();
manager.notify(1, notification);
相关文章推荐
- 预览功能
- Topshelf入门
- HDU 1175 连连看 (搜索,dfs)
- 关于服务号的模板消息发送接口种种
- 开发高性能的MongoDB应用—浅谈MongoDB性能优化
- ubuntu 系统备份
- TCP/IP网络体系结构
- Dapper with MVC MiniProfiler
- 数据结构算法——单链表的三种插入
- LayoutSubViews setNeedsLayout setNeedsdisplay
- Oracle对象之表和索引的介绍
- jdbc预编译和批处理sql
- 配置WebLogic Server 11g 集群、Session复制(Windows)
- JQuery获取与设置HTML元素的内容或文本的实现代码
- 报表工具记录
- C/C++复习:数组作实参,指针作形参排序
- 投票选举
- java MD5算法 代码
- 对“视觉机器学习20讲配套仿真代码”的研究心得---EM算法
- repeater 删除确认框 传多个参数