关于通知栏的使用:

Notification及NotificationManager的使用详解

相关类:

import android.app.NotificationManager;
import android.app.PendingIntent;

import android.app.Notification;

1、使用标准的布局来显示通知信息

  1. Intent intent = new Intent(MainActivity.this, Other.class);
  2. PendingIntent pi = PendingIntent.getActivity(MainActivity.this,
  3. 0, intent, 0);
  4. Notification notify = new Notification();
  5. notify.icon = R.drawable.ic_launcher; // 通知狼的两个图标
  6. notify.tickerText = "启动其他activity的通知"; // 通知栏浮动的时候显示的信息
  7. notify.when = System.currentTimeMillis();   //设置时间
  8. notify.defaults = Notification.DEFAULT_SOUND; //默认的声音
  9. notify.defaults = Notification.DEFAULT_ALL;
  10. notify.setLatestEventInfo(MainActivity.this, "普通通知 ", "点击查看",pi);//使用标准的布局来显示通知信息
  11. NotificationManager no = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  12. no.notify(NOTIFICATION_ID, notify);

2、使用RemoteViews自定义布局

  1. Intent intent = new Intent(MainActivity.this,Other.class);
  2. //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  3. PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
  4. Notification notification = new Notification();
  5. notification.tickerText="fadf";
  6. notification.icon=R.drawable.ic_action_search;
  7. RemoteViews  contentview = new RemoteViews(getPackageName(),R.layout.status_bar_balloon);
  8. //这种是你自定义一个布局进行显示的。
  9. contentview.setTextViewText(R.id.text, "你好吧");
  10. contentview.setImageViewResource(R.id.icon, R.drawable.ic_action_search);
  11. //在视图中添加图片和文本进行显示。
  12. notification.contentView = contentview ;
  13. NotificationManager  ni = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  14. ni.notify(NOTIFICATION_ID, notification);

3、带参数的Notification构造方法实现通知

  1. Intent intent = new Intent(MainActivity.this,Other.class);
  2. //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  3. PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
  4. Notification notification = new Notification(R.drawable.ic_action_search,"fadf",SystemClock.currentThreadTimeMillis());
  5. //这一种里面的构造方法,可以理解为使用默认的布局进行现实的,显示图标,滚动图标的显示内容,以及显示时间。
  6. notification.setLatestEventInfo(MainActivity.this,"你好", "还不错", pi); //在通知栏中现实的内容
  7. NotificationManager  ni = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  8. ni.notify(NOTIFICATION_ID, notification);

android 随手记 广播通知栏 二的更多相关文章

  1. Android笔记(二十六) Android中的广播——BroadcastReceiver

    为了方便进行系统级别的消息通知,Android有一套类似广播的消息机制,每个应用程序都可以对自己感兴趣的广播进行注册,这样该程序就只会接收自己所关心的广播内容,这些广播可能是来自于系统,也可能是来自于 ...

  2. Android入门(八)广播

    原文链接:http://www.orlion.ga/572/ 一.广播机制 Android中的每个应用程序都可以对自己感兴趣的广播进行注册,这样该程序就只会接收到自己所关心的广播内容,这些广 播可能是 ...

  3. Android开发之广播

    广播是Android开发中的一个重要的功能,在Android里面有各式各样的广播,比如:电池的状态变化.信号的强弱状态.电话的接听和短信的接收等等,现在给大家简单介绍一下系统发送.监听这些广播的机制. ...

  4. Android实现点击通知栏后,先启动应用再打开目标Activity ,极光推送等推送的也可以参考一下(转)

    我因为项目中集成了极光推送,推送的通知栏点开需要确定进入哪个界面就参考了这边文章,感谢作者的无私. 标签: 情况简述 在开发Android app的过程中,遇到这样一个需求:app中启动一个Servi ...

  5. Android入门:广播发送者与广播接收者

    参考: Android入门:广播发送者与广播接收者 - xiazdong - CSDN博客http://blog.csdn.net/xiazdong/article/details/7768807 一 ...

  6. Android中的广播Broadcast详解

    今天来看一下Android中的广播机制,我们知道广播Broadcast是Android中的四大组件之一,可见他的重要性了,当然它的用途也很大的,比如一些系统的广播:电量低.开机.锁屏等一些操作都会发送 ...

  7. android之自定义广播

    布局文件 点击按钮发送广播 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln ...

  8. Android之旅---广播(BroadCast)

    什么是广播 在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.我们拿广播电台来做个比方.我们平常使用收音机收音是这样的:许许多多不同的广播电台通过特定的频率来发送他们 ...

  9. Android系列之网络(二)----HTTP请求头与响应头

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

随机推荐

  1. Linux 性能分析工具 nmon for Linux

    http://blog.csdn.net/defonds/article/details/41725929 http://blog.csdn.net/fansy1990/article/details ...

  2. Android微信智能心跳方案

    前言:在13年11月中旬时,因为基础组件组人手紧张,Leo安排我和春哥去广州轮岗支援.刚到广州的时候,Ray让我和春哥对Line和WhatsApp的心跳机制进行分析.我和春哥抓包测试了差不多两个多礼拜 ...

  3. Java_Activiti5_菜鸟也来学Activiti5工作流_之JUnit单元测试(四)

    /**ActivitiSpringJuinitTest.java * author : 冯孟活 ^_^ * dates : 2015年9月2日 下午2:16:54 * class : activiti ...

  4. Looper Handler MessageQueue Message 探究

    Android消息处理的大致的原理如下: 1.有一个消息队列,可以往队列中添加消息 2.有一个消息循环,可以从消息队列中取出消息 Android系统中这些工作主要由Looper和Handler两个类来 ...

  5. angularjs-ngModel 控制页面的宽度

    js NiDialog.open({ windowClass: '', size:'elements', backdrop: 'static', keyboard: false, templateUr ...

  6. linq学习笔记:将List<T> 转换为 Dictionary<T Key,T Value>

    运用Linq,将List<T> 转换为 Dictionary<T Key,T Value> 即:List<T>  ToDictionary<T Key,T V ...

  7. C#操作数据库,将其查查出来的记录条数显示在winform窗体中的方法之一

    //1.数据库链接的基本操作(略) //2.创建对象函数(关键部分) sqlConn.Open(); //初始化定义记录条数 ; object obj = sqlComm.ExecuteScalar( ...

  8. Proxy 模式

    在以下集中情况下可以用 Proxy模式解决问题: 1)创建开销大的对象时候,比如显示一幅大的图片,我们将这个创建的过程交给代理去完成,GoF 称之为虚代理(Virtual Proxy): 2)为网络上 ...

  9. SGU 135.Drawing Lines

    水题,不说了. #include <iostream> using namespace std; int f[70000]={1}; int n; int main(){ cin>& ...

  10. Jquery实现图片左右滚动(自动)

    <!DOCTYPE HTML><html><head><title>基于jQuery的控制左右滚动效果_自动滚动版本</title>< ...