发送通知:Notification
Intent的主要功能是完成一个Activity跳转到其他Activity或者是Service的操作,表示的是一种
操作的意图。
PendingIntent表示的是暂时执行的一种意图,是一种在产生某一事件之后才进行操作的Intent对象。
面试题:请解释Intent与PendingIntent的区别:
Intent表示立即执行;
PendingIntent表示暂缓执行,遇到特殊条件才执行。
发送通知:Notification
Notification表示一种提示用户操作的组件。
Notification表示的是一个通知,而NotificationManager表示的是一个发送通知的操作类。
在main.xml中:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="#000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#ffffff"
android:text="请看上面的通知!"/>
</LinearLayout>
在MyNotificationDemo.java中:
package com.li.notification;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MyNotificationDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
NotificationManager notificationManager =
(NotificationManager)super.getSystemService(Activity
.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.pic_m,"来自李叶文的消息",
System.currentTimeMillis()); //立刻发送一个消息
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, super.getIntent(), PendingIntent
.FLAG_CANCEL_CURRENT); //创建了一个PendingIntent对象
notification.setLatestEventInfo(this, "广西", "北海", contentIntent);
notificationManager.notify("LYW",R.drawable.pic_m,notification);
}
}
发送通知:Notification的更多相关文章
- 浏览器桌面通知--Notification
前言 最近项目上要用到浏览器桌面通知,之前虽然知道有这个东西,但是一直没有用过,借此机会了解下桌面通知的机制,在此分享下. 1.权限 首先需要明确的是,不是所有网页都可以发桌面通知的,不然不得烦死,那 ...
- 向通知栏发送通知点击跳转并传递数据(PendingIntent)传递数据
// 为发送通知的按钮的点击事件定义事件处理方法 public void send() {///// 第一步:获取NotificationManager NotificationManager nm ...
- Android中的通知—Notification 自定义通知
Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...
- iOS的通知Notification
这里是不同的对象之间的通知, 不是本地通知. 一开始玩, 很挠头, 后来发现原来只是对象init的过程出了问题. 首先, 新建一个简单的单controller的工程. 然后打开它的ViewContro ...
- Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。
常用的程序通知,显示到主页面的顶部栏. package com.lixu.tongzhi; import android.app.Activity; import android.app.Notifi ...
- Swift - 使用NSNotificationCenter发送通知,接收通知
转载自:http://www.mamicode.com/info-detail-1069228.html 标签: 1,通知(NSNotification)介绍 这里所说的通知不是指发给用户看的通知消息 ...
- 通知栏发送消息Notification(可以使用自定义的布局)
一个简单的应用场景:假如用户打开Activity以后,按Home键,此时Activity 进入-> onPause() -> onStop() 不可见.代码在此时机发送一个Notifica ...
- 状态栏通知Notification的简单使用
今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...
- 通知 Notification 详解
效果 通知栏-刚收到通知时 通知栏-收到通知几秒后 标准视图 大视图-下滑前是标准视图 大视图-下滑后显示大视图 自定义通知 讲解 Notification,俗称通知,是一种具有全局效果的通知,它展示 ...
随机推荐
- Web常用函数介绍(LoadRunner相关)
介绍大纲:1. web_url2. web_image3. web_link4. web_submmit_form 详细介绍: 一. web_url web_url 语法: Int Web_url(c ...
- Linux内核中常见内存分配函数(二)
常用内存分配函数 __get_free_pages unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order) __get_f ...
- Android的读写文件权限
设置文件生成的权限: public static boolean saveInfo( Context context, String userName, String userPass, int mo ...
- c/c++性能优化--- cache优化的一点杂谈
之前写了一篇关于c/c++优化的一点建议,被各种拍砖和吐槽,有赞成的有反对的,还有中立的,网友对那篇博客的的评论和吐槽,我一个都没有删掉,包括一些具有攻击性的言论.笔者有幸阅读过IBM某个项目的框架代 ...
- 你知道为什么Xcode6中Swift没有智能提示和自己主动补全功能吗 ?
你知道为什么Xcode6中Swift没有智能提示和自己主动补全功能吗 ? 长沙戴维营教育将为你解开这个巨大的谜团大BUG! http://www.ubuntucollege.cn/course/29/ ...
- javascript如何判断访问网页的设备及是否支持触屏功能
var system ={}; var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac ...
- RCTF Welpwn
Welpwn 很久以前的了,现在整理一下 题目的漏洞很明显,就是一个栈溢出.程序打开了NX,却没有给libc.重点是,在向栈上拷贝数据时,如果输入中含有'\x00',会被截断,对利用漏洞造成了困难.虽 ...
- Angular初级入门
1:jquery :库 -一般是封装了一些方法 -我们去调用他的这些方法分 2:angular:框架 -框架是提供了一些规则或者模式 -我们是根据这一种规则或者模式去写代码 -然后接下来就由angul ...
- 【转】这些隐藏在苹果iPhone当中的内置代码你是否知道?
原文地址:http://www.ithome.com/html/iphone/200569.htm 每一部手机都有一些内置的隐藏代码,我们称之为“指令”,这些代码加在一起就叫做“指令集”.当然这些代码 ...
- python基础:映射和集合类型
python字典的迭代器遍历 字典有一个方法可以返回该字典的迭代器,这个方法就是: dict. iteritems() 当在字典中增加或者删除字典entry的时候,迭代器会失效的,类似于C++的stl ...