Android开发之PendingIntent的使用
来源:互联网 发布:d3.js api详解 编辑:程序博客网 时间:2024/06/13 11:00
原链接http://www.cnblogs.com/liyiran/p/4656821.html
官网关于该类的继承关系,PendingIntent继承自Object。因为该类为final,所以没有子类,无法被继承。
要想得到一个PendindIntent对象,需要使用方法类的静态方法 getActivity(Context, int, Intent, int),getActivities(Context, int, Intent[], int),getBroadcast(Context, int, Intent, int),getService(Context, int, Intent, int)
这几个静态方法分别对应着Intent的行为,跳转到Activity,Activities,Broadcast,Service。
这4个静态方法的参数都一样,其中第一个和第三个参数比较的重要,其次是第二个和第四个。第一个参数传入当前的context,第三个参数传入intent.
PendingIntent是一个特殊的Intent,主要区别是intent是立马执行,PendingIntent是待确定的Intent。PendingIntent的操作实际上是传入的intent的操作。
使用pendingIntent的目的主要是用于所包含的intent执行是否满足某些条件。
主要的地方:Notification,SmsManager,AlarmManager等
1.Notification例子:
1 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) 2 mBuilder.setSmallIcon(R.drawable.notification_icon) 3 mBuilder.setContentTitle("My notification") 4 mBuilder.setContentText("Hello World!"); 5 Intent resultIntent = new Intent(this, ResultActivity.class); 6 PendingIntent resultPendingIntent = PendingIntent.getActivity(this,0,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT); 7 mBuilder.setContentIntent(resultPendingIntent); 8 int mNotificationId = 001; 9 // Gets an instance of the NotificationManager service10 NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);11 // Builds the notification and issues it.12 mNotifyMgr.notify(mNotificationId, mBuilder.build());
2.SmsManager例子:
1 SmsManager smsManage = SmsManager.getDefault();2 Intent intent=new Intent("SEND_SMS_ACTION");3 PendingIntent pendingIntent=PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);4 smsManage.sendTextMessage("13xxxxxxxxx", null, "这是一条短信", pendingIntent, null);
主要常量
FLAG_CANCEL_CURRENT:如果当前系统中已经存在一个相同的PendingIntent对象,那么就将先将已有的PendingIntent取消,然后重新生成一个PendingIntent对象。
FLAG_NO_CREATE:如果当前系统中不存在相同的PendingIntent对象,系统将不会创建该PendingIntent对象而是直接返回null。
FLAG_ONE_SHOT:该PendingIntent只作用一次。在该PendingIntent对象通过send()方法触发过后,PendingIntent将自动调用cancel()进行销毁,那么如果你再调用send()方法的话,系统将会返回一个SendIntentException。
FLAG_UPDATE_CURRENT:如果系统中有一个和你描述的PendingIntent对等的PendingInent,那么系统将使用该PendingIntent对象,但是会使用新的Intent来更新之前PendingIntent中的Intent对象数据,例如更新Intent中的Extras。
详细:http://blog.csdn.net/hudashi/article/details/7060837
- Android开发之PendingIntent的使用
- android之PendingIntent的使用
- android之PendingIntent使用
- Android PendingIntent的使用
- PendingIntent android.app.PendingIntent.getActivity的使用
- android开发之Notification结合PendingIntent使用小结
- Android之pendingIntent的介绍
- android开发中关于PendingIntent的知识点
- Android开发-对于PendingIntent的简单理解
- Android之PendingIntent的深入理解
- Android PendingIntent使用的特殊情况
- Android中PendingIntent的简单使用
- Android 之 PendingIntent(一)
- Android 之 PendingIntent(二)
- Android之Pendingintent学习
- Android之PendingIntent
- Android PendingIntent的理解
- PendingIntent的使用
- L3 使用PuTTY,xshell远程连接Linux及PuTTY,xshell密钥认证
- AI世界:2018年八大趋势
- Android用jsoup解析html
- 微信开发返回【10003】错误
- post 与get 区别,为什么现在的HTTP通信中大多数请求还是使用get?
- Android开发之PendingIntent的使用
- 设计模式-原型模式
- Linux安装NodeJS
- 一张图说明各个开源协议的不同
- Maven profile实现多环境配置
- [干货]作为大数据入门者_你不得不知道的2017杭州云栖大会
- .NET与JAVA的区别【完整版】
- pip install opencv-python opencv-contrib-python 不可用时,可使用whl的方式安装
- Existing Linux Wireless drivers