首页 技术 正文
技术 2022年11月6日
0 收藏 860 点赞 260 浏览 1129 个字

PendingIntent的Flags的类型:

  1. * Flags的类型:
  2. FLAG_ONE_SHOT:得到的pi只能使用一次,第二次使用该pi时报错
  3. FLAG_NO_CREATE: 当pi不存在时,不创建,返回null
  4. FLAG_CANCEL_CURRENT: 每次都创建一个新的pi
  5. FLAG_UPDATE_CURRENT: 不存在时就创建,创建好了以后就一直用它,每次使用时都会更新pi的数据(使用较多)
  6. * 在AlarmManager中的使用
  7. Intent intent = new Intent(“action”, null, context, serviceClass);
  8. PendingIntent pi = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  9. AlarmManager manager = (AlarmManager)probe.getSystemService(Context.ALARM_SERVICE);
  10. manager.set(AlarmManager.RTC_WAKEUP, milis, pi);
  11. * 在NotificationManager中的使用
  12. Intent intent = new Intent();
  13. intent.setAction(“myaction”);
  14. PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  15. NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  16. Notification n = new Notification();
  17. n.icon = R.drawable.ic_launcher;
  18. n.when = System.currentTimeMillis();
  19. n.setLatestEventInfo(this,”this is title”, “this is a message”, pi);
  20. nm.notify(0, n);

* send()方法是用,调用PendingIntent.send()会启动包装的Intent(如启动service,activity)

* cancel()方法是为了解除PendingIntent和被包装的Intent之间的关联,此时如果再调用send()方法,则会抛出CanceledException异常

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898