毕业工作已经快半年了,打算在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

更多相关文章

  1. 创建第一个Andorid程序
  2. Android(安卓)studio创建java项目
  3. Android(安卓)网络请求简单使用方式
  4. Android推送通知
  5. Android(安卓)Studio 使用笔记(1) -- 设置自动生成serialVersionUI
  6. Android快速实现发送邮件
  7. Android(六)通知、样式、主题、HTML
  8. Android之Broadcast Receiver的两种注册方式
  9. 详解android四种布局之LinearLayout

随机推荐

  1. eBook 功能模块二之设置模块Android
  2. [置顶] Android(安卓)从硬件到应用:一步一
  3. Android性能测试
  4. Android随想
  5. Android面经:二流Android攻城狮用一个月面
  6. 丢失Android系统库或者Conversion to Dal
  7. android 如何监听自身应用被卸载
  8. 【Android 1.6】View和ViewGroup的touch
  9. android RelativeLayout属性和使用, 实现
  10. Android开发之旅:活动与任务