首页 第7章AndroidBroadcastReceiver组件

第7章AndroidBroadcastReceiver组件

举报
开通vip

第7章AndroidBroadcastReceiver组件第7章BroadcastReceiver组件7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学发送广播sendBroadcast(intent)接收广播。四喜丸子之一---广播接收者BroadcastReceiver。类似于事件处理。不过事件处理是同一个程序内部,而广播的处理机制则是系统级别的(...

第7章AndroidBroadcastReceiver组件
第7章BroadcastReceiver组件7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学发送广播sendBroadcast(intent)接收广播。四喜丸子之一---广播接收者BroadcastReceiver。类似于事件处理。不过事件处理是同一个程序内部,而广播的处理机制则是系统级别的(可用于不同应用程序之间)。实现方式为:写个类继承BroadcastReceiver,覆盖 方法 快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载 onReceive()在配置文件中配置7.1广播,BroadcastReceiver概述要发送广播给广播接收者,同样需要信使Intent。系统内置了一些与广播接收者有关的IntentActionandroid.provider.Telephony.SMS_RECEIVEDIntent.ACTION_TIME_CHANGED(时间改变时)Intent.ACTION_BOOT_COMPLETED(系统启动完成时)Intent.ACTION_PACKAGE_ADDED(添加包时—即安装程序)android中使用package来区分不同的应用程序Intent.ACTION_BATTERY_CHANGED(电量低时)7.1广播,BroadcastReceiver概述7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学书上实例不好。没有体现出在不同应用程序之间发送广播和接收广播。实例:7.2自定义BroadcastReceiver在第一个Android项目中,发送广播7.2自定义BroadcastReceiver在第二个Android项目中,接收广播7.2自定义BroadcastReceiver实例注意事项将SelfBroadcastA项目和SelfBroadcastB项目部署在模拟器上运行SelfBroadcastA项目SelfBroadcastA执行发送广播命令7.2自定义BroadcastReceiver实例注意事项两个项目都需要安装到Android系统中,才能看到效果两个项目的包名不能一样,否则后安装的那个将覆盖掉前面那个。(Android用包来区分应用程序)7.2自定义BroadcastReceiver7.2自定义BroadcastReceiver7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学Broadcast被分为如下两种:NormalBroadcast(普通广播)OrderedBroadcast(有序广播)Context提供如下两个方法发送广播sendBroadcast()sendOrderedBroadcast()7.3有序广播项目实例演示SortedBroadcast课堂编程实现7.3有序广播7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学除了可以自定义广播事件之外,Android还提供了许多标准的广播Action。这些广播由系统在某种情形下自动发出,程序员只需要定义BroadcastReceiver进行接收即可。7.4接收系统内置广播事件7.4接收系统内置广播事件系统内置广播Action常量常量名称含义ACTION_BOOT_COMPLEMENTED系统启动完成时(开机)ACTION_TIME_CHANGED系统时间改变ACTION_DATE_CHANGED日期改变ACTION_BATERY_LOW电量低…..添加包卸载包…..实例(Sysbroadcast)--设置系统时间,自定义广播接收者来接收时间被改变事件。7.4接收系统内置广播事件实例--设置系统时间,自定义广播接收者来接收时间被改变事件。注册BroadcastReceiver7.4接收系统内置广播事件实例--设置系统时间,自定义广播接收者来接收时间被改变事件。7.4接收系统内置广播事件实例--SMSBroadcast。7.4接收系统内置广播事件7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学广播接收者收到广播之后,如何获取用户的注意(通知用户)?简单的Toast.makeText().show()并不行..例如:手机电量不足,如何接收了该广播之后,来提示用户呢?应该闪光、发声、振动等..此时最好的选择是使用通知Notification和通知管理者NotificationManager7.5使用Notification和NotificationManager通知用户7.5使用Notification和NotificationManager通知用户项目实例1演示Notification1代码分析,使用Notificaiton发送通知的步骤:调用getSystemService(NOTIFICATION_SERVICE)获取系统的NotificationManager通过构造器创建一个Notificaiton对象为Notificaiton设置各种属性通过NotificationManager发送Notificaiton7.5使用Notification和NotificationManager通知用户由于使用Notification和NotificationManager是做可视化操作,一般需要在Activity中写代码。涉及知识:Intent和PendingIntent:Intent是你的意图,比如你想启动一个Activity,就会通过Intent来描述启动这个Activity的某些特点,让系统找到这个Activity来启动,而不是启动别的。Activity.StartActivity(intent)就会立即启动这个ActivityPendingIntent呢?Penging中文意思就是:待定,将来发生或来临。PendingIntent不像Intent那样立即发生,而是在合适的时候由另外的程序去触发所包装的Intent。7.5使用Notification和NotificationManager通知用户Intent和PendingIntent:7.5使用Notification和NotificationManager通知用户Notification和NotificationManager及BroadcastReceiver综合实例(与BroadcastReceiver结合)Notification27.5使用Notification和NotificationManager通知用户7.1Broadcast及BroadcastReceiver概述7.2自定义BroadcastReceiver7.3有序广播7.4接收系统内置广播事件7.5使用Notification和NotificationManager通知用户7.6闹钟AlarmManager本章导学实现方式:获取AlarmManagergetSystemService(Context.ALARMSERVICE);定义Intent—封装目标(广播接收者),定义PendingIntent—在闹钟闹的时候,再去激发Intent调用AlarmManager的方法,设置闹的时间等。7.6闹钟AlarmManager实例AlarmManager7.6闹钟AlarmManager实例7.6闹钟AlarmManager实例7.6闹钟AlarmManager演讲完毕,谢谢观看!
本文档为【第7章AndroidBroadcastReceiver组件】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
言言无悔一生
暂无简介~
格式:ppt
大小:951KB
软件:PowerPoint
页数:34
分类:
上传时间:2022-01-21
浏览量:0