Notification封装(没做从网络下载)
1.Notification作为消息通知,这里简单封装了使用
建立一个bean
package com.jcut.view; /**
* Author:JsonLu
* DateTime:2016/2/26 14:25
* Email:jsonlu@qq.com
* Desc:
**/
public class NotificationModel { private String NTitle;
private String NContent;
private long NWhen;
private String NTicker;
private int NType;
private String NIcon; public String getNTitle() {
return NTitle;
} public void setNTitle(String NTitle) {
this.NTitle = NTitle;
} public String getNContent() {
return NContent;
} public void setNContent(String NContent) {
this.NContent = NContent;
} public long getNWhen() {
return NWhen;
} public void setNWhen(long NWhen) {
this.NWhen = NWhen;
} public String getNTicker() {
return NTicker;
} public void setNTicker(String NTicker) {
this.NTicker = NTicker;
} public int getNType() {
return NType;
} public void setNType(int NType) {
this.NType = NType;
} public String getNIcon() {
return NIcon;
} public void setNIcon(String NIcon) {
this.NIcon = NIcon;
}
}
简单的Notification 的封装
package com.jcut.view; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.support.v7.app.NotificationCompat; import com.example.jcut.R; /**
* Author:JsonLu
* DateTime:2016/2/26 12:46
* Email:jsonlu@qq.com
* Desc:
**/
public class Notification extends NotificationCompat { private Builder mBuilder; public Notification(Context context) {
mBuilder = new Builder(context);
} public Notification(Context context, NotificationModel model) {
mBuilder = new Builder(context);
mBuilder.setContentTitle(model.getNTitle())
.setContentText(model.getNContent())
.setTicker(model.getNTicker())
.setWhen(model.getNWhen())
.setPriority(PRIORITY_DEFAULT)
.setOngoing(false)
.setDefaults(model.getNType())
.setSmallIcon(R.drawable.ic_launcher);//此处要下载图片到本地
} public Builder getmBuilder() {
return mBuilder;
} public void setContentIntent(CallBack call) {
mBuilder.setContentIntent(call.getPendingIntent());
} public void notify(int notifyId, NotificationManager manager) {
android.app.Notification notify = mBuilder.build();
notify.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(notifyId, notify);
} public interface CallBack {
PendingIntent getPendingIntent();
}
}
简单的Test
public void showButtonNotify() {
Notification customNot = new Notification(this);
NotificationCompat.Builder mBuilder = customNot.getmBuilder();
mBuilder.setContentTitle("测试标题")//设置通知栏标题
.setContentText("测试内容") //设置通知栏显示内容
.setTicker("测试通知来啦") //通知首次出现在通知栏,带上升动画效果的
.setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间
.setPriority(PRIORITY_DEFAULT) //设置该通知优先级
.setOngoing(false)//ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)
.setDefaults(DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合
// Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE permission
.setSmallIcon(R.mipmap.ic_launcher);//设置通知小ICON customNot.setContentIntent(new CallBackImpl());
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
customNot.notify(1, mNotificationManager);
} public PendingIntent getDefalutIntent(int flags) {
Intent notificationIntent = new Intent(this, TestActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
return contentIntent;
} class CallBackImpl implements Notification.CallBack {
@Override
public PendingIntent getPendingIntent() {
return getDefalutIntent(1);
}
}
Notification封装(没做从网络下载)的更多相关文章
- WorldWind源码剖析系列:网络下载类WebDownload
网络下载类WebDownload封装了对请求的瓦片进行网络下载的相关操作.该类使用了两个委托类型和一个枚举类型. 该类的类图如下. 网络下载类WebDownload各个字段和属性的含义说明如下: st ...
- 用python做youtube自动化下载器 代码
目录 项目地址 思路 流程 1. post i. 先把post中的headers格式化 ii.然后把参数也格式化 iii. 最后再执行requests库的post请求 iv. 封装成一个函数 2. 调 ...
- [搜片神器]直接从DHT网络下载BT种子的方法
DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr DHT系 ...
- android 图片网络下载github开源框架之Universal-Image-Loader
最近在做妙趣剪纸项目,剪纸应用项目链接.发扬传统文化,大家多多关注. 需要自己搭建服务器,我用的是新浪sae,简直秒杀京东云几条街,把图片放在网上下载,但是图片经常下载要遇到很多问题,包括oom等.所 ...
- [No000079]罗辑思维2016.1.2日前的所有每日语音,python3做的网络爬虫
源码地址:https://github.com/charygao/Download_the_LouJiSiWei 写过很久了,vision1.0里有不少bug,今天重新整理修改了一下,运行了一下,2个 ...
- 没做过编译器就是被人欺——从一道变态的i++题猜编译器的行为(表达式从左往右扫描,同一变量相互影响)
首先不要被人蒙了,如果是这样,根本编译不过: int i=1; int b=i+++++i; printf("%d %d\n", b ,i); Mingw报错:error: lva ...
- 关于一些没做出来的SBCF题
这里是一些我SB没做出来的CF水题. 其实这些题思维量还不错,所以写在这里常来看看…… 不一定每题代码都会写. CF1143C Queen 其实只要注意到如果一个点开始能被删,那一直就能被删:一个点开 ...
- 所有流媒体协议,编解码规范和媒体封装格式的datasheet的下载地址
https://github.com/jiayayao/DataSheet All datasheet about stream protocol, encode-decode spec and me ...
- 【腾讯敏捷转型No.5】需求没做完可以发布嘛
很多人对于敏捷的第一直觉就是“快”,开发快,测试快,发布快,并不知道如何把这个“快”应用到敏捷实践中,下面我们来分析一下导致工作效率低的核心原因.没有使用敏捷之前,在大多数情况下,项目管理都需要开各种 ...
随机推荐
- 提高Order by语句查询效率的两个思路
提高Order by语句查询效率的两个思路 2011-03-01 13:07 水太深 ITPUB 字号:T | T 在MySQL数据库中,Order by语句的使用频率是比较高的.但是众所周知,在使用 ...
- Vue 2.0基础
我们将会选择使用一些vue周边的库vue-cli, vue-router,vue-resource,vuex 1.使用vue-cli创建项目2.使用vue-router实现单页路由3.用vuex管理我 ...
- 关于win8.1“连接被远程计算机关闭”的一种解决方案
我就是连接的时候出现"连接被远程计算机关闭",然后想着可能是win8更新之后网络协议 出问题了,后来无意中发现e信在第一次启动的时候会在网络适配器中会多出很多网卡,其中三个是带感叹 ...
- ubuntu各版本的区别
ubuntu.kubuntu以及xubuntu的区别Ubuntu默认是Gnome:KUbuntu用的是KDE,效果比较炫目,但是系统要求也较高XUbuntu用的是Xface,比较轻量,系统要求较低,推 ...
- requirejs 合并方案
http://snandy.iteye.com/blog/1595464 http://www.cnblogs.com/snandy/archive/2012/03/05/2378105.html h ...
- [置顶] 推荐12款很棒的HTML5开发框架和开发工具
HTML5 在不同的领域让网页设计更强大的.快速,安全,响应式,互动和美丽,这些优点吸引更多的 Web 开发人员使用 HTML5.HTML5 有许多新的特性功能,允许开发人员和设计师创建应用程序和网站 ...
- java面向对象值类属语句块
在我们之前学习语句的时候,我们讲过一种比较特殊的语句块,那就是局部代码块.局部代码块的作用是什么呢,就是把临时使用的变量放在里面,之后执行完之后,局部代码块中定义的变量会直接被释放,这样就避免了那些我 ...
- Delphi调用webservice总结
Delphi调用webservice总结 Delphi调用C#写的webservice 用delphi的THTTPRIO控件调用了c#写的webservice. 下面是我调试时遇到的一些问题: ...
- C语言的强制类型转换
1.什么是强制类型转换:遇到一些类型不同的一些数据之间的表达运算 ,需要将较高的数据类型转换成较低类型时. 2.强制类型的形式: (强制转换的类型)(表达式): 2.强制类型的使用: float a, ...
- android EditText监听事件及参数详解
editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence ...