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/ ...
随机推荐
- java输入输出
1. import java.io.*;//写进文档,然后又在显示器显示出来.public class fileinputstream{public static void main(String[] ...
- Fragment的懒加载
我们在做应用开发的时候,一个Activity里面可能会以viewpager(或其他容器)与多个Fragment来组合使用,而如果每个fragment都需要去加载数据,或从本地加载,或从网络加载,那么在 ...
- <legend>标签
健康信息身高: 体重: 如果表单周围没有边框,说明您的浏览器太老了. <!DOCTYPE HTML> <html> <body> <form> < ...
- SQL Server 事务、异常
转自: http://www.cnblogs.com/moss_tan_jun/archive/2011/11/26/2263988.html 事务 在数据库中有时候需要把多个步骤的指令当作一个整 ...
- mysql - 编码
show variables like 'character%'; 通过以上命令可以查询编码情况, 不过,在安装的时候,建议选择‘gbk’这类中文编码, 如果选择的是utf8,则在处理的过程中需要进行 ...
- ZBar Installer
ZBar Install.For windows:http://sourceforge.net/projects/zbar/files/zbar/0.10/zbar-0.10-setup.exe/do ...
- Ubuntu Server 14.04 下root无法ssh登陆
今天安装了Ubuntu Server 14.04 在终端配置了root密码后,使用SecureCRT和putty竟然不能ssh登陆,SecureCRT一直提示密码不对,但是可以肯定输入的密码100 ...
- SGU 174.wall
题意: 判断给出的线段是否组成了多边形. Solution: 简单题,并查集+hash 这里用map实现 code #include <iostream> #include <cst ...
- chrome调试状态下动态加载的js
在js文件中加入 //@ sourceURL=文件名.js
- Windows7 IIS7 无法启动计算机上的服务W3SVC如何修复
错误提示 启动iis7管理服务器提示:无法启动计算机上的服务W3SVC 启动Windows Process Activation Service服务,报错:6801 指定资源管理器中的事务支持未启动或 ...