1.Notification作为消息通知,这里简单封装了使用

建立一个bean

  1. package com.jcut.view;
  2.  
  3. /**
  4. * Author:JsonLu
  5. * DateTime:2016/2/26 14:25
  6. * Email:jsonlu@qq.com
  7. * Desc:
  8. **/
  9. public class NotificationModel {
  10.  
  11. private String NTitle;
  12. private String NContent;
  13. private long NWhen;
  14. private String NTicker;
  15. private int NType;
  16. private String NIcon;
  17.  
  18. public String getNTitle() {
  19. return NTitle;
  20. }
  21.  
  22. public void setNTitle(String NTitle) {
  23. this.NTitle = NTitle;
  24. }
  25.  
  26. public String getNContent() {
  27. return NContent;
  28. }
  29.  
  30. public void setNContent(String NContent) {
  31. this.NContent = NContent;
  32. }
  33.  
  34. public long getNWhen() {
  35. return NWhen;
  36. }
  37.  
  38. public void setNWhen(long NWhen) {
  39. this.NWhen = NWhen;
  40. }
  41.  
  42. public String getNTicker() {
  43. return NTicker;
  44. }
  45.  
  46. public void setNTicker(String NTicker) {
  47. this.NTicker = NTicker;
  48. }
  49.  
  50. public int getNType() {
  51. return NType;
  52. }
  53.  
  54. public void setNType(int NType) {
  55. this.NType = NType;
  56. }
  57.  
  58. public String getNIcon() {
  59. return NIcon;
  60. }
  61.  
  62. public void setNIcon(String NIcon) {
  63. this.NIcon = NIcon;
  64. }
  65. }

简单的Notification 的封装

  1. package com.jcut.view;
  2.  
  3. import android.app.NotificationManager;
  4. import android.app.PendingIntent;
  5. import android.content.Context;
  6. import android.support.v7.app.NotificationCompat;
  7.  
  8. import com.example.jcut.R;
  9.  
  10. /**
  11. * Author:JsonLu
  12. * DateTime:2016/2/26 12:46
  13. * Email:jsonlu@qq.com
  14. * Desc:
  15. **/
  16. public class Notification extends NotificationCompat {
  17.  
  18. private Builder mBuilder;
  19.  
  20. public Notification(Context context) {
  21. mBuilder = new Builder(context);
  22. }
  23.  
  24. public Notification(Context context, NotificationModel model) {
  25. mBuilder = new Builder(context);
  26. mBuilder.setContentTitle(model.getNTitle())
  27. .setContentText(model.getNContent())
  28. .setTicker(model.getNTicker())
  29. .setWhen(model.getNWhen())
  30. .setPriority(PRIORITY_DEFAULT)
  31. .setOngoing(false)
  32. .setDefaults(model.getNType())
  33. .setSmallIcon(R.drawable.ic_launcher);//此处要下载图片到本地
  34. }
  35.  
  36. public Builder getmBuilder() {
  37. return mBuilder;
  38. }
  39.  
  40. public void setContentIntent(CallBack call) {
  41. mBuilder.setContentIntent(call.getPendingIntent());
  42. }
  43.  
  44. public void notify(int notifyId, NotificationManager manager) {
  45. android.app.Notification notify = mBuilder.build();
  46. notify.flags = Notification.FLAG_AUTO_CANCEL;
  47. manager.notify(notifyId, notify);
  48. }
  49.  
  50. public interface CallBack {
  51. PendingIntent getPendingIntent();
  52. }
  53. }

简单的Test

  1. public void showButtonNotify() {
  2. Notification customNot = new Notification(this);
  3. NotificationCompat.Builder mBuilder = customNot.getmBuilder();
  4. mBuilder.setContentTitle("测试标题")//设置通知栏标题
  5. .setContentText("测试内容") //设置通知栏显示内容
  6. .setTicker("测试通知来啦") //通知首次出现在通知栏,带上升动画效果的
  7. .setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间
  8. .setPriority(PRIORITY_DEFAULT) //设置该通知优先级
  9. .setOngoing(false)//ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)
  10. .setDefaults(DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合
  11. // Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE permission
  12. .setSmallIcon(R.mipmap.ic_launcher);//设置通知小ICON
  13.  
  14. customNot.setContentIntent(new CallBackImpl());
  15. NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  16. customNot.notify(1, mNotificationManager);
  17. }
  18.  
  19. public PendingIntent getDefalutIntent(int flags) {
  20. Intent notificationIntent = new Intent(this, TestActivity.class);
  21. notificationIntent.setAction(Intent.ACTION_MAIN);
  22. notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  23. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  24. return contentIntent;
  25. }
  26.  
  27. class CallBackImpl implements Notification.CallBack {
  28. @Override
  29. public PendingIntent getPendingIntent() {
  30. return getDefalutIntent(1);
  31. }
  32. }

Notification封装(没做从网络下载)的更多相关文章

  1. WorldWind源码剖析系列:网络下载类WebDownload

    网络下载类WebDownload封装了对请求的瓦片进行网络下载的相关操作.该类使用了两个委托类型和一个枚举类型. 该类的类图如下. 网络下载类WebDownload各个字段和属性的含义说明如下: st ...

  2. 用python做youtube自动化下载器 代码

    目录 项目地址 思路 流程 1. post i. 先把post中的headers格式化 ii.然后把参数也格式化 iii. 最后再执行requests库的post请求 iv. 封装成一个函数 2. 调 ...

  3. [搜片神器]直接从DHT网络下载BT种子的方法

    DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr DHT系 ...

  4. android 图片网络下载github开源框架之Universal-Image-Loader

    最近在做妙趣剪纸项目,剪纸应用项目链接.发扬传统文化,大家多多关注. 需要自己搭建服务器,我用的是新浪sae,简直秒杀京东云几条街,把图片放在网上下载,但是图片经常下载要遇到很多问题,包括oom等.所 ...

  5. [No000079]罗辑思维2016.1.2日前的所有每日语音,python3做的网络爬虫

    源码地址:https://github.com/charygao/Download_the_LouJiSiWei 写过很久了,vision1.0里有不少bug,今天重新整理修改了一下,运行了一下,2个 ...

  6. 没做过编译器就是被人欺——从一道变态的i++题猜编译器的行为(表达式从左往右扫描,同一变量相互影响)

    首先不要被人蒙了,如果是这样,根本编译不过: int i=1; int b=i+++++i; printf("%d %d\n", b ,i); Mingw报错:error: lva ...

  7. 关于一些没做出来的SBCF题

    这里是一些我SB没做出来的CF水题. 其实这些题思维量还不错,所以写在这里常来看看…… 不一定每题代码都会写. CF1143C Queen 其实只要注意到如果一个点开始能被删,那一直就能被删:一个点开 ...

  8. 所有流媒体协议,编解码规范和媒体封装格式的datasheet的下载地址

    https://github.com/jiayayao/DataSheet All datasheet about stream protocol, encode-decode spec and me ...

  9. 【腾讯敏捷转型No.5】需求没做完可以发布嘛

    很多人对于敏捷的第一直觉就是“快”,开发快,测试快,发布快,并不知道如何把这个“快”应用到敏捷实践中,下面我们来分析一下导致工作效率低的核心原因.没有使用敏捷之前,在大多数情况下,项目管理都需要开各种 ...

随机推荐

  1. iscc2016-basic-find-to-me

    额 第一题就暴力搜索了 已知仿射加密变换为c=(11m+8)mod26,试对密文sjoyuxzr解密 #include <stdio.h> int main(void) { int m,c ...

  2. 转:LESS CSS 框架简介

    原文来自于:http://www.ibm.com/developerworks/cn/web/1207_zhaoch_lesscss/ 简介 CSS(层叠样式表)是一门历史悠久的标记性语言,同 HTM ...

  3. CMD模块定义规范

    CMD 模块定义规范 在 Sea.js 中,所有 JavaScript 模块都遵循 CMD(Common Module Definition) 模块定义规范.该规范明确了模块的基本书写格式和基本交互规 ...

  4. dt dd 如何在同一行上

    <style> dl{clear:left;} dt,dd{float:left;} </style> <dl> <dt>test </dt> ...

  5. “adb server is out of date. killing.... ADB server didn't ACK * failed to start daemon * ”

    草泥马的adb: “adb server is out of date. killing.... ADB server didn't ACK * failed to start daemon * ” ...

  6. 【ZOJ】3430 Detect the Virus

    动态建树MLE.模仿别人的代码模板各种原因wa后,终于AC. #include <iostream> #include <cstdio> #include <cstrin ...

  7. C++学习之容器的摸索

    初学容器,容易犯错的地方 1.vector,list和deque都是顺序容器.其中vector和deque都可以通过下标访问,而list不能 2. 容器的begin和end操作 c.begin()返回 ...

  8. ASP.NET网站文件上传下载功能

    if (!IsPostBack) { if (Application["RaNum"] == null) { Random ra = new Random(); Applicati ...

  9. MySQL错误代码大全

    130 :文件格式不正确.(还不是很清楚错误的状况)145  :文件无法打开.1005:创建表失败.1006:创建数据库失败.1007:数据库已存在,创建数据库失败.1008:数据库不存在,删除数据库 ...

  10. 《程序设计中的组合数学》——polya计数

    我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...