在发送一个Notification前,我们需要准备好一个NotificationManager

NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

notification = new Notification();

1、定义一个Notification具备的三个基本参数icon,tickerText,以及添加打开关闭方式

notification.icon = R.drawable.ic_launcher;
notification.tickerText = "注意了,我被扔到状态栏了";
 
notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击通知之后自动消失
notification.defaults=notification.DEFAULT_SOUND|notification.DEFAULT_VIBRATE; //notification被notify的时候,触发默认声音和默认震动
 
2、为notification添加一个意图(Intent):
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
notification.contentIntent = contentIntent;
 
由于Notification的包装内容为Intent,我们就可以方便地为通知被点击的触发的事件传值:
openintent.putExtra("isRead", true);
openintent.putExtra("name", "CaiYu");
 
4、发送通知
manager.notify(notifacation_id, notification);//notifacation_id由自己指定,为每一个Notification对应的唯一标志
 
5、自定义通知栏
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notify_view);//自定义的layout
contentView.setImageViewResource(R.id.notify_imageLog, R.drawable.ic_launcher);//layout中的控件
contentView.setTextViewText(R.id.notify_name, "1");
notification.contentView = contentView;
 
6、删除、更改某些通知
manager.cancel(notifacation_id);
manager.cancelAll();
manager.notify(notifaction_id,newNotification);
 
7、用notification.builder实现
NotificationCompat.Builder builder = new Builder(context);
builder.setContent(remoteViews).setSmallIcon(R.drawable.icon).setLargeIcon(icon).setOngoing(true).setTicker("music is playing");
manager.notify(notifaction_id, builder.build());      
 

android Notification总结的更多相关文章

  1. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  2. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

  3. 3、android notification 详细用法

    在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以确认保存成功. * 如果应用程序在后台 ...

  4. android notification 传值关键

    android notification 传值关键在 onNewIntent方法里获取 @Override protected void onCreate(Bundle savedInstanceSt ...

  5. Android NOtification 使用(震动 闪屏 铃声)

    一. Notification 简介 在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以 ...

  6. Android Notification通知详细解释

    Android Notification通知具体解释  Notification: (一).简单介绍:         显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...

  7. Android Notification实现推送消息过程中接受到消息端有声音及震动及亮屏提示

    在Android Notification状态栏通知一文中,简单实现了消息的推送效果,这里就接着上文说一下,当用户接受到消息时的提示效果 // 5-增加震动及声音及亮屏 notification.de ...

  8. Android Notification通知简介

    Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...

  9. Android Notification状态栏通知

    没有添加额外的震动及声音效果,这里直接实现了通知的功能,看效果吧: MainActivity.java package com.example.notification; import android ...

  10. Android Notification 消息通知 相关资料.md

    目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...

随机推荐

  1. mybatis的一种批量更新方法【我】

    接手一个项目,项目主要架构用的 servlet 3.0 + spring + mybatis 其中发现一个问题: 操作数据时,批量插入可以,批量更新,使用各种写法都无法成功,直接报 mybatis转换 ...

  2. Vuex速学篇:(2)利用state保存新闻数据

    回顾 以前我们在做这个新闻列表的时候,是一个写死的数据 export default{ data(){ return{ newslist:[ {newsid:"101",pubti ...

  3. POJ 3352 Road Construction ; POJ 3177 Redundant Paths (双联通)

    这两题好像是一样的,就是3177要去掉重边. 但是为什么要去重边呢??????我认为如果有重边的话,应该也要考虑在内才是. 这两题我用了求割边,在去掉割边,用DFS缩点. 有大神说用Tarjan,不过 ...

  4. POJ 1971 Parallelogram Counting (Hash)

          Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6895   Acc ...

  5. Vue(小案例)底部tab栏和顶部title栏的实现

    ---恢复内容开始--- 一.前言 1.底部tab栏实现 2.顶部title栏实现 二.主要内容   1.底部tab栏实现(将底部导航提取到公共的组件中) 具体效果:当点击切换不同的tab的时候,对应 ...

  6. Calendar 类 案例 和 闰年的计算

    Calendar 类 是一个抽象类 getInstance()直接返回子类对象 直接调用 主要方法:get set add 代码如下: package cn.lijun.demo; import ja ...

  7. day12-(jsp&el&jstl)

    回顾: jsp: cookie: 浏览器端会话技术 由服务器产生,生成key=value形式,通过响应头(set-cookie)返回给浏览器,保存在浏览器端 下次访问的时候根据一定的规则携带cooki ...

  8. Centos7使用kubeadm 安装多主高可用kubernets:v.1.11集群

    实验环境介绍: 本次实验环境是5个节点 3台master 2台node节点: k8smaster01 192.168.111.128 软件:etcd k8smaster haproxy keepali ...

  9. mysql错误汇集

    [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated.. ...

  10. layui打印html页面转成pdf

    <!DOCTYPE html><html lang="zh"><head>     <meta charset="UTF-8&q ...