- 浏览: 662569 次
- 性别:
- 来自: 安徽
文章分类
- 全部博客 (252)
- Html/Div+CSS (12)
- Js/Jquery (34)
- Flex (2)
- Ajax (3)
- Java (35)
- C# (15)
- Spring (16)
- Hibernate (13)
- Struts2 (12)
- Struts1 (7)
- DWR (1)
- iBatis/myBatis (9)
- Tag(JSTL、EL) (1)
- Android (44)
- SQL (7)
- SEO (7)
- Exception (3)
- Tool (10)
- Other (3)
- WebService (9)
- Apache (7)
- Ext (0)
- Utils (12)
- thinking in programme (2)
- Hadoop (0)
- ActiveMQ (0)
- HTML5/CSS3 (0)
- WPF (1)
- NodeJs (1)
- 设计模式 (0)
- 程序人生 (1)
- 随笔 (1)
- Linux (1)
- Load Balance (0)
最新评论
-
drinkjava2:
太复杂了而且不通用,利用ThreadLocal可完美解决这一问 ...
JDBC的多条件动态查询 -
u013107014:
multipartRequest.getFiles(" ...
多文件上传 by MultipartFile and Multiple -
liyys:
可惜没讲你mysql数据库的表的设计
iBatis入门 -
Mapple_leave:
效果还是挺不错的,谢谢了。
中文简体与繁体的转换 -
arcpad:
JS禁用浏览器退格键
Intent 的主要功能是表示用户的一种操作意图,使用 Intent 之后将立即执行用户所有需要的操作,但是在 Android 中也提供了一个 PendingIntent 操纵,表示将要发生的操作。苏伟将要发生的 Intent 是指在当前的 Activity 不立即使用此 Intent 进行处理,而将此 Intent 封装后传递给其他 Activity 程序,而其他 Activity 程序在需要使用此 Intent 时才进行操作。
Intent :表示立刻执行;
PendintIntent :表示的是暂缓执行,遇到特殊条件才执行;
PendingIntent 与 Intent 没有任何继承关系,所以这两个类表示两种不同的 Intent 操作,其方法和常量有:
No. |
常量及方法 |
描述 |
1 |
Public static final int FLAG_CANCEL_CURRENT |
重新生成一个新的 PendingIntent 对象 |
2 |
Public static final int FLAG_NO_CREATE |
如果不存在 PendingIntent 对象,则创建一个新的 |
3 |
Public static final int FLAG_ONE_SHOT |
创建的 PendingIntent 对象只使用一次 |
4 |
Public static final int FLAG_UPDATE_CURRENT |
如果 PendingIntent 对象已经存在,则直接使用,并且实例化一个新的 Intent 对象 |
5 |
Public static PendingIntent getActivity(Context context, Int requestCode,Intent intent,int flags) |
通过 PendingIntent 启动一个新的 Activity |
6 |
Public static PendingIntent getBroadcast(Context context, Int requestCode,Intent intent,int flags) |
通过 PendingIntent 启动一个新的 Broadcast |
7 |
Public static PendingIntent getService(Context context, Int requestCode,Intent intent,int flags) |
通过 PendingIntent 启动一个新的 Service |
在 Android 操作系统中,狠毒地方都要使用 PendingIntent 类,如发送一些用户的通知( Notification )或者为用户发送短信( SMS )等都会使用到此类。
一、发送通知: Notification
Androd.app.Notification 与 Toast 类似,可以直接在 Android 手机屏幕的最上面显示通知信息。使用 Notification 定义一条提示信息的标题、时间、内容以及具体的触发操作
No. |
方法 |
类型 |
描述 |
1 |
Public Notification(nt icon,CharSequence tickerText,long when) |
构造 |
创建一个新的 Notification 对象,并指定提示的图标、信息内容及显示的时间,如果为立刻显示,则直接使用 System.currentTimeMillis() 设置 |
2 |
Public void setLatestEventInfo(Context context,CharSequence contentTitle,CharSequence contentText,PendingIntent contentIntent) |
普通 |
设置通知的标题、内容以及指定的 PendingIntent |
然后我们再通过 android.app.NotificationManager 类,该类就相当于一个发布 Notification 信息的组件,如果把 NotificationManager 类看作一个新闻广播,那么每个 Notification 就可以看作一条条的新闻信息。 NotificationManager 常用方法如下:
No. |
方法 |
描述 |
1 |
Public void notify(String tag,int id, Notification notification) |
指定发送信息的标签、显示图标、 Notification 对象 |
2 |
Public void notify(int id, Notification notification) |
指定发送信息的显示图标、 Notification 对象 |
3 |
Public void cancel(String tag,int id) |
取消指定标签、显示图标的信息 |
4 |
Public void cancel(int id) |
取消指定图标的信息 |
5 |
Public void cancelAll() |
取消所有信息 |
范例:
PendingIntent01_NotificationActivity.java
package com.iflytek.demo; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.os.Bundle; public class PendingIntent01_NotificationActivity extends Activity { /** Called when the activity is first created. */ @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.ic_launcher, "来自XDWANG的消息。", System.currentTimeMillis()); // 立刻发送一个消息,信息图标、信息提示、显示时间 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, super.getIntent(), PendingIntent.FLAG_UPDATE_CURRENT); // 创建了一个PendingIntent对象 notification.setLatestEventInfo(this, "王旭东", "http://xdwangiflytek.iteye.com", contentIntent);// 信息标题、信息内容、待发送的Intent notificationManager.notify("XDWANG", R.drawable.ic_launcher, notification);// 设置信息标签、设置图标、发送消息 } }
效果:
二、 SMS 服务
前面我们说过 Intent 启动手机短信发送程序,其主要功能只是显示一个发送短信的窗口,而要想发送短信,用户需要手动进行,在 Android 中专门提供了一个 android.telephony.SmsManager 类,可以进行短信发送程序的调用
No. |
方法 |
描述 |
1 |
Public ArrayList<String>divideMessage(String text) |
拆分短信内容 |
2 |
Public static SmsManager getDefault() |
取得默认手机的 SmsManager 对象 |
3 |
Public void sendTextMessage(String destinationAddress,String scAddress,String text,PendingIntent sendIntent, PendingIntent diliveryIntent) |
发送文字信息 |
4 |
Public void sendMulipartTextMessage(String destinationAddress, String scAddress,ArrayList<String>parts,ArrayList<PendingIntent> sentIntents,ArrayList<PendingIntent> deliveryIntents) |
发送多条文字信息 |
5 |
Public void sendDataMessage(String destinationAddress,String scAddress,short destinationPort,byte[] data,PendintIntent sendIntent,PendingIntent deliveryIntent) |
发送二进制数据信息 |
说明: destinationAddress :收件人地址
scAddress :设置短信中心的号码,如果设置为 null ,则为默认中心号码
text :指定发送短信的内容
sentIntent :当消息发出时,通过 PendingIntent 来广播发送成功或者失败的信息报告,如果该参数为空,则检查所有未知的应用程序,这样将导致发生发送时间延长
deliveryIntent :当信心发送到收件处时,该 PendingIntent 会进行广播
范例:
PendingIntent02_SMSActivity.java
package com.iflytek.demo; import java.util.Iterator; import java.util.List; import android.app.Activity; import android.app.PendingIntent; import android.os.Bundle; import android.telephony.SmsManager; import android.widget.Toast; public class PendingIntent02_SMSActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.main); // 短信内容 String content = "在昨天国防部例行记者会上,钓鱼岛问题依然是关注焦点。有记者提到,有媒体报道日本航空自卫队近半年来出动战斗机达到200余次,在日本政府宣布购岛行为之后剧增到54次,为前三个月的3.6倍,请问如何评论,在这方面中方采取了哪些措施?近年来,日本自卫队飞机针对中国的侦巡力度不断加大,损害了中国的主权权益和安全利益,也是引发中日海空安全问题的根源。国防部新闻事务局副局长、国防部新闻发言人杨宇军说,我们要求日方停止侵犯中国的主权权益,同时采取有效措施,避免和防止海空事故和不测事件的发生。";// 超过了70个字 // 短信管理类 SmsManager smsManager = SmsManager.getDefault(); // 取得PendingIntent PendingIntent sentIntent = PendingIntent.getActivity(this, 0, super.getIntent(), PendingIntent.FLAG_UPDATE_CURRENT); if (content.length() > 70) { // 大于70个字,拆分 List<String> msgs = smsManager.divideMessage(content); // 拆分信息 Iterator<String> iterator = msgs.iterator();// 实例化Iterator while (iterator.hasNext()) {// 迭代输出 String msg = iterator.next();// 取出每一个子信息 smsManager.sendTextMessage("13956027313", null, msg, sentIntent, null);// 发送文字信息 } } else {//如果不大于70,则直接全部发送 smsManager.sendTextMessage("13956027313", null, content, sentIntent, null); } Toast.makeText(this, "短信发送完成", Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { sentIntent.cancel(); super.onDestroy(); } }
添加权限:
<uses-permission android:name="android.permission.SEND_SMS" />
发表评论
-
This version of ADT requires android SDK
2013-07-25 16:45 1536Windows系统下用Eclipse开发工具开发An ... -
Android学习13-----网络通信(4) WebView组件
2012-11-27 09:18 2452WebView 是一个开发的浏览 ... -
Android学习13-----网络通信(3) 与Web Service进行通讯
2012-11-26 09:40 1856这里我们的WebService使用xFire开发。 ... -
Android学习13-----网络通信(2) 与Socket交换数据
2012-11-23 09:11 3267对于网络开发而言,最常用的交互模式:WebService、We ... -
Android学习13-----网络通信(1) 与WEB服务器交换数据
2012-11-22 09:11 2157与Web服务器交互: 如果手机要想与 web ... -
Android学习11-----多媒体技术(5) 媒体录制
2012-11-16 08:10 1844在Android中通过android.media ... -
Android学习11-----多媒体技术(4) 使用摄像头拍照,多点触控
2012-11-15 08:37 2831一、摄像头拍照 前面说媒体播放 时了解了 ... -
Android学习11-----多媒体技术(3) 媒体播放
2012-11-14 08:25 1378在 Androi ... -
Android学习11-----多媒体技术(2) Animation
2012-11-13 08:47 1955一、渐变动画, Tweened Animation ... -
Android学习11-----多媒体技术(1) 绘制简单图形,Bitmap,Matrix
2012-11-12 08:48 1564一、绘制简单图 ... -
Android学习12-----手机服务(4) 传感器
2012-11-19 09:13 1986传感器一般用于游戏中,在 Android 系统中为 ... -
Android学习12-----手机服务(1) 取得电池电量和声音服务:AudioManager
2012-11-18 11:18 3427一、取得电池电量信息 ... -
Android学习10-----Android组件通信 (8) 桌面显示组件:AppWidget
2012-11-02 08:36 1996一、 AppWidget 在使用 Androi ... -
Android学习10-----Android组件通信 (7) 广播机制:Broadcast
2012-11-01 08:43 1477一、 广播: 广播也是一种信息的发送机制,在 ... -
Android学习10-----Android组件通信 (5) Service
2012-10-30 08:25 1673Service 基本组成: ... -
Android学习10-----Android组件通信 (4) 消息机制
2012-10-29 08:22 1508在 Android 操作系统中存在着消息队列的操作 ... -
Android学习10-----Android组件通信 (3) ActivityGroup
2012-10-26 08:23 2261导航栏在 Android 中的应用是很常见的,前面 ... -
Android学习10-----Android组件通信 (2) Activity生命周期
2012-10-25 08:16 1246Activity 是整个 Android 平台的基 ... -
Android学习10-----Android组件通信 (1) Intent
2012-10-24 08:43 1923在一个项目之中,会由多个 Activity ... -
Android判断是否有网络连接
2013-04-25 16:34 1401Android中判断有时候因为功能的需求,需要判断是否有网络 ...
相关推荐
实现可定时响起的闹钟----PendingIntent 与 AlarmManager 的运用
NULL 博文链接:https://sunzone.iteye.com/blog/1998091
Android中pendingIntent的深入理解
android的服务以及通知的小例子 个人存档 代码笔记见http://blog.sina.com.cn/s/blog_70356c200100y9pf.html
自制发送短信程序--SmsManager与PendingIntent类的使用
本文实例讲述了Android编程实现PendingIntent控制多个闹钟的方法。分享给大家供大家参考,具体如下: 要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)来实现控制多...
Android中PendingIntent的简要介绍.pdf 学习资料 复习资料 教学资源
android 自制发送短信程序 SmsManager与PendingIntent对象
import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; /*必需引用telephony.gsm.SmsManager类才能使用sendTextMessage()*/ import android.telephony.SmsManager; ...
主要介绍了Android中pendingIntent的深入分析的相关资料,需要的朋友可以参考下
博客《详解PendingIntent》所涉及的源码,这是博客中所说的有问题的PendingIntent对应原源代码
这样我们就可以画出如下示意图:PendingIntent 只能通过下列的静态方法获取//获取Broadcast关联的PendingIntent PendingI
buildSimple(int id,int icon,CharSequence contentTitle ,CharSequence contentText,PendingIntent contentIntent) buildProgress(int id,int icon,CharSequence contentTitle,int progress,int max,String format...
《Android开发艺术探索》侧重于Android知识的体系化和系统工作机制的分析,通过《Android开发艺术探索》的学习可以极大地提高开发者的Android技术水平,从而更加高效地成为高级开发者。而对于高级开发者来说,仍然...
android-闹钟 使用 AlarmManager、BroadcastReceiver 和 PendingIntent 的重复 Android 警报的简单示例
1.5.3 Android基础组件 1.5.4 高级UI概念 1.5.5 Android Service组件 1.5.6 Android媒体和电话组件 1.5.7 Android Java包 1.6 利用Android源代码 1.7 本书的示例项目 1.8 小结 第2章 设置...
根据本讲学习内容,学会运用AlarmManager和PendingIntent实现定时提醒功能。 (1) 提交的作业包中含有应用程序运行效果截图。