android 随手记 广播通知栏 二
关于通知栏的使用:
Notification及NotificationManager的使用详解
相关类:
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Notification;
1、使用标准的布局来显示通知信息
- Intent intent = new Intent(MainActivity.this, Other.class);
- PendingIntent pi = PendingIntent.getActivity(MainActivity.this,
- 0, intent, 0);
- Notification notify = new Notification();
- notify.icon = R.drawable.ic_launcher; // 通知狼的两个图标
- notify.tickerText = "启动其他activity的通知"; // 通知栏浮动的时候显示的信息
- notify.when = System.currentTimeMillis(); //设置时间
- notify.defaults = Notification.DEFAULT_SOUND; //默认的声音
- notify.defaults = Notification.DEFAULT_ALL;
- notify.setLatestEventInfo(MainActivity.this, "普通通知 ", "点击查看",pi);//使用标准的布局来显示通知信息
- NotificationManager no = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- no.notify(NOTIFICATION_ID, notify);
2、使用RemoteViews自定义布局
- Intent intent = new Intent(MainActivity.this,Other.class);
- //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
- Notification notification = new Notification();
- notification.tickerText="fadf";
- notification.icon=R.drawable.ic_action_search;
- RemoteViews contentview = new RemoteViews(getPackageName(),R.layout.status_bar_balloon);
- //这种是你自定义一个布局进行显示的。
- contentview.setTextViewText(R.id.text, "你好吧");
- contentview.setImageViewResource(R.id.icon, R.drawable.ic_action_search);
- //在视图中添加图片和文本进行显示。
- notification.contentView = contentview ;
- NotificationManager ni = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- ni.notify(NOTIFICATION_ID, notification);
3、带参数的Notification构造方法实现通知
- Intent intent = new Intent(MainActivity.this,Other.class);
- //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
- Notification notification = new Notification(R.drawable.ic_action_search,"fadf",SystemClock.currentThreadTimeMillis());
- //这一种里面的构造方法,可以理解为使用默认的布局进行现实的,显示图标,滚动图标的显示内容,以及显示时间。
- notification.setLatestEventInfo(MainActivity.this,"你好", "还不错", pi); //在通知栏中现实的内容
- NotificationManager ni = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- ni.notify(NOTIFICATION_ID, notification);
android 随手记 广播通知栏 二的更多相关文章
- Android笔记(二十六) Android中的广播——BroadcastReceiver
为了方便进行系统级别的消息通知,Android有一套类似广播的消息机制,每个应用程序都可以对自己感兴趣的广播进行注册,这样该程序就只会接收自己所关心的广播内容,这些广播可能是来自于系统,也可能是来自于 ...
- Android入门(八)广播
原文链接:http://www.orlion.ga/572/ 一.广播机制 Android中的每个应用程序都可以对自己感兴趣的广播进行注册,这样该程序就只会接收到自己所关心的广播内容,这些广 播可能是 ...
- Android开发之广播
广播是Android开发中的一个重要的功能,在Android里面有各式各样的广播,比如:电池的状态变化.信号的强弱状态.电话的接听和短信的接收等等,现在给大家简单介绍一下系统发送.监听这些广播的机制. ...
- Android实现点击通知栏后,先启动应用再打开目标Activity ,极光推送等推送的也可以参考一下(转)
我因为项目中集成了极光推送,推送的通知栏点开需要确定进入哪个界面就参考了这边文章,感谢作者的无私. 标签: 情况简述 在开发Android app的过程中,遇到这样一个需求:app中启动一个Servi ...
- Android入门:广播发送者与广播接收者
参考: Android入门:广播发送者与广播接收者 - xiazdong - CSDN博客http://blog.csdn.net/xiazdong/article/details/7768807 一 ...
- Android中的广播Broadcast详解
今天来看一下Android中的广播机制,我们知道广播Broadcast是Android中的四大组件之一,可见他的重要性了,当然它的用途也很大的,比如一些系统的广播:电量低.开机.锁屏等一些操作都会发送 ...
- android之自定义广播
布局文件 点击按钮发送广播 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln ...
- Android之旅---广播(BroadCast)
什么是广播 在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.我们拿广播电台来做个比方.我们平常使用收音机收音是这样的:许许多多不同的广播电台通过特定的频率来发送他们 ...
- Android系列之网络(二)----HTTP请求头与响应头
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
随机推荐
- LINUX 内核调试基础+编程基础
http://blog.chinaunix.net/uid-20564848-id-73208.html 内核文档:[root@localhost Documentation]# pwd /usr/s ...
- Android(java)学习笔记212:中文乱码的问题处理(qq登录案例)
1.我们在之前的笔记中LoginServlet.java中,我们Tomcat服务器回复给客户端的数据是英文的"Login Success","Login Failed&q ...
- css 权威指南笔记( 五)结构和层叠之三种样式来源
CSS中的样式一共有三种来源:创作人员.读者和用户代理,来源的不同会影响到样式的层叠方式 首先,创作人员(author's+style)样式应该是我们最熟悉的,如果你是一个前端开发者,那么你写的那些样 ...
- sublime text插件
BracketHighlighter : 该插件提供配对标签,或大括号或字符引号的配对高亮显示,加强系统高亮 SublimeTmpl: 文件模版.安装后,文件---> New File (Sub ...
- asp.net下载文件的几种方法
最近做东西遇到了下载相关的问题.在这里总结一下自己处理的方法. 1.以字节流的形式向页面输出数据以下载Excel为例子. string path=Server.MapPath("文件路径&q ...
- 绝对炫的幻灯片插件-SKITTER
绝对炫的幻灯片插件-SKITTER 所属分类:媒体-幻灯片和轮播图,图片展示,滑块和旋转 Includes code source // Styles <link href="css/ ...
- js的MVC结构设计
基于jquery的Deferred,设计出如下MVC架构. 模型model interface.js interface: function(userid){ var dtd = $.Deferred ...
- 【转】纯 CSS 实现高度与宽度成比例的效果
先来演示页面:Demo; 转的内容: 最近在做一个产品列表页面,布局如右图所示.页面中有若干个 item,其中每个 item 都向左浮动,并包含在自适应浏览器窗口宽度的父元素中. item 元素的 C ...
- Log4j(1.2.17) - hello world
1. Maven 依赖 <dependencies> <dependency> <groupId>log4j</groupId> <artifac ...
- Store update, insert, or delete statement affected an unexpected number of rows ({0}).
问题描述 Store update, insert, or delete statement affected an unexpected number of rows ({0}). Entities ...