发送广播简易工具类
来源:互联网 发布:计算机数据库研究生 编辑:程序博客网 时间:2024/06/05 00:19
/** * 发送广播简易工具类 * Created by Liam on 2015/4/2. */public class BroadcastUtil { /** * 构造函数设为private,防止外部实例化 */ private void BroadcastManager() { } /** * 注册广播接收器 * * @param ctx Context(不可空) * @param iReceiver IReceiver(不可空) * @param action Intent.Action(不可空) */ public static void registerReceiver(Context ctx, final IReceiver iReceiver, final String action) { if (ctx == null || iReceiver == null || action == null) throw new IllegalArgumentException("使用registerReceiver()注册广播时,参数Context、IReceiver和Action不能为空!"); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { iReceiver.onReceive(context, intent); } }; IntentFilter filter = new IntentFilter(action); ctx.registerReceiver(receiver, filter); } /** * 发送广播 * * @param ctx Context(不可空) * @param i Intent(可为null),不需要设置Action,请把Action作为参数传入 * @param action Intent.Action(不可空) */ public static void send(Context ctx, Intent i, final String action) { if (ctx == null || action == null) throw new IllegalArgumentException("使用send()发送广播时,参数Context和Action不能为空!"); if (i == null) i = new Intent(); i.setAction(action); ctx.sendBroadcast(i); } /** * 接收广播的页面需要实现,把接收后的操作覆写在OnReceive()方法里 */ public interface IReceiver { void onReceive(Context ctx, Intent intent); }}
0 0
- 发送广播简易工具类
- 简易工具类笔记
- 简易加密工具类
- 简易Http工具类
- 广播发送
- 发送广播
- 广播发送
- Android-BroadCastReceiverUtil(广播工具类)
- 广播发送者/广播接收者
- 发送广播和接收广播
- 广播接收者-发送有序广播
- 广播接收者---发送有序广播
- 广播流程2--发送广播
- email发送工具类
- 邮件发送工具类
- 发送短信工具类
- 邮件发送工具类
- 发送邮件工具类
- UIevent事件
- Hadoop环境搭建
- The const of C/C++
- python查询数据库结果返回
- Android Fragment应用实战,使用碎片向ActivityGroup说再见
- 发送广播简易工具类
- VC中三种获取本地时间的方式
- java中断言(assert)应用
- html5 postMessage解决跨域、跨窗口消息传递
- LeetCode Restore IP Addresses
- filter过滤实例知识
- sql 删除 空记录
- WEKA使用教程
- java单点登录的实现