关于android的Notification的若干问题
来源:互联网 发布:windows sdk v8.1下载 编辑:程序博客网 时间:2024/05/22 01:58
毕业工作已经快半年了,打算在2016年开始总结自己平时在工作终于到的android方面的问题。今年遇到的第一个问题就是关于android的通知栏的问题。
在创建Notification的时候,总共有三种不同的方式。
(1)普遍的创建方式(通用)setLatestEventInfo(Context,”“,content,pendingIntent);
(2)在API11以后的创建方式。NotificationCompat.getNotification()
(3)在API11以后的创建方式。NotificationCompat.build()
在创建Notification当然也可以指定自己的布局文件。比如音乐播放器的Notification。当然创建自定义布局的Notification不在本文的讨论范围内。
我今天要说的是如何在通知中显示若干行内容。我们做常见的通知是这样的。如图1
我今天要实现的样式:
代码如下:
*
private void createNotification(int id,String title,String content) { BitmapDrawable drawable = ((BitmapDrawable)(getResources().getDrawable(R.drawable.ic_launcher))); Bitmap bitmap = drawable.getBitmap(); Intent intent = new Intent(NNApplication.getInstance(), ClickNotificationReceiver.class); intent.putExtra(ORDER_ID,orderId); //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getBroadcast(NNApplication.getInstance(), id, intent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager manager = (NotificationManager) NNApplication.getInstance().getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = null; if(!CommonUtils.checkIsXiaoMi()) { NotificationCompat.Builder builder = new NotificationCompat.Builder(NNApplication.getInstance()); notification = builder.setTicker(“XXXXX”).setContentTitle(“XXXXX”) .setSmallIcon(R.drawable.ic_launcher).setLargeIcon(bitmap).setWhen(System.currentTimeMillis()) .setStyle(new NotificationCompat.BigTextStyle().bigText(“采薇采薇,薇亦柔止。曰归曰归,心亦忧止。 忧心烈烈,载饥载渴。我戍未定,靡使归聘。”) ).setContentIntent(pendingIntent).setPriority(Integer.MAX_VALUE). setWhen(System.currentTimeMillis()).build(); } else { notification = new Notification(); notification.icon = R.drawable.ic_launcher; notification.tickerText = “XXX”; notification.when = System.currentTimeMillis(); notification.contentIntent = pendingIntent; notification.setLatestEventInfo(NNApplication.getInstance(),”XXX”,content,pendingIntent); } //用于当点击完通知以后,直接使通知消失。 notification.flags = Notification.FLAG_AUTO_CANCEL; notification.defaults = Notification.DEFAULT_SOUND; manager.notify(1, notification); }
*
在上面的生成Notification加了个逻辑判断,即当前的系统是否是小米系统,如果是小米系统则只能按照第一种方法创建Notification。
第一次写博客,写的不好,望海涵。
以下是参考文献:
1.http://blog.csdn.net/loongggdroid/article/details/17616509
2.http://www.2cto.com/kf/201502/374946.html
3.http://stackoverflow.com/questions/14602072/styling-notification-inboxstyle
- 关于android的Notification的若干问题
- 关于android联网的若干问题
- Android起步 - 关于Eclipse的若干问题
- 关于Winpcap的若干问题
- 关于DLL的若干问题
- 关于DES的若干问题:
- 关于fusionchart的若干问题
- 关于aotutrace 的若干问题
- 关于ARM的若干问题
- 关于CSpreadSheet的若干问题
- 关于指针的若干问题
- 关于fopen的若干问题
- 关于webview的若干问题
- 关于ListView的若干问题
- 关于ABST2的若干问题
- 关于CSpreadSheet的若干问题
- 关于Slidingmenu的若干问题
- 关于递归的若干问题
- 为什么要使用HibernateCallback
- Maven查找依赖树,解决jar包冲突问题
- LeetCode 191 Number of 1 Bits(1 比特的数字们)
- Memcached服务器安装、配置
- 【tyvj1208】最长不下降子序列2
- 关于android的Notification的若干问题
- 汇智网node学习笔记
- 《从零开始自学iOS》_03
- Xcode7 网络请求报错:The resource could not be loaded because the App Transport Security policy requir
- 数据库性能优化
- Android程序的调试-输出日志信息的几种方法
- 对象的克隆——原型模式(三):浅克隆,深克隆
- Spring 学习笔记整合 Hibernate
- 在服务中注册广播接受者