Android中的静态系统广播和动态系统广播
来源:互联网 发布:摇钱树捕鱼游戏源码 编辑:程序博客网 时间:2024/05/17 23:27
Android4.4:
静态广播:
可在AndroidManifest.xml中定义,不需程序启动即可接收,可用作自动启动程序
Intent.ACTION_BOOT_COMPLETED //系统启动完成
Intent.ACTION_MEDIA_MOUNTED //SD卡挂载
Intent.ACTION_MEDIA_UNMOUNTED //SD卡卸载
Intent.ACTION_USER_PRESENT//解除锁屏
ConnectivityManager.CONNECTIVITY_ACTION//网络状态变化
<receiver android:name=".StaticBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_MOUNTED"/> <action android:name="android.intent.action.MEDIA_UNMOUNTED"/> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="file" /> </intent-filter> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /><action android:name="android.intent.action.USER_PRESENT" /> </intent-filter></receiver>
public class StaticBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubif (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){Log.d(TAG, "onReceive boot: ");Intent new_intent = new Intent(context,TestLauncher.class);//popup the activitynew_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(new_intent);}else if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {Log.d(TAG, "onReceive ACTION_USER_PRESENT: ");}}}
动态广播:
只能在代码中注册,程序适应系统变化做操作,程序运行状态才能接收到
Intent.ACTION_SCREEN_ON //屏幕亮
Intent.ACTION_SCREEN_OFF //屏幕灭
Intent.ACTION_TIME_TICK //时间变化 每分钟一次
<span style="white-space:pre"></span> IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_TIME_TICK); registerReceiver(new DynamicBroadcastReceiver(), filter);
0 0
- Android中的静态系统广播和动态系统广播
- Android中的静态系统广播和动态系统广播
- Android中的静态系统广播和动态系统广播
- Android中的静态系统广播与动态系统广播及其相应的注册与接收
- android 中的广播 ,系统广播和自定义广播
- android中的系统广播
- android中的系统广播
- Android 广播BroadcastReceiver静态/动态注册,获取系统电量广播【开机广播】,获取网络状态广播,Timer的使用简介
- 静态广播和动态广播
- Android系统中的常用广播
- Android中的系统广播集合
- Android中的系统广播集合
- Android中的系统广播集合
- Android中的系统广播集合
- Android中的系统广播集合
- Android中的系统广播集合
- Android 接收系统发送的广播,动态注册和静态注册
- 广播的动态注册和静态注册以及系统广播的使用!
- 20140915 N2
- 隐藏内核模块的方法
- SharePoint學習
- Spring事务配置的五种方式
- ios程序启动方式判断方法
- Android中的静态系统广播和动态系统广播
- android 使用相机时出现了 startpreview 报错
- 前端性能优化最佳实践
- XSS跨站测试代码大全
- 扩展EasyUI datagrid 增加表头右键菜单功能,可动态对列进行显示和隐藏
- Android延时执行的几种方法
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- OSX中使用Remote Desktop Connection时 终端服务器超出了最大允许连接数 mstsc /admin
- 设计一个LRU cache