Android中的静态系统广播和动态系统广播
2015-06-17 21:49
489 查看
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//网络状态变化
[html] view
plaincopy
<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>
[java] view
plaincopy
public class StaticBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Log.d(TAG, "onReceive boot: ");
Intent new_intent = new Intent(context,TestLauncher.class);
//popup the activity
new_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 //时间变化 每分钟一次
[java] view
plaincopy
静态广播:
可在AndroidManifest.xml中定义,不需程序启动即可接收,可用作自动启动程序
Intent.ACTION_BOOT_COMPLETED //系统启动完成
Intent.ACTION_MEDIA_MOUNTED //SD卡挂载
Intent.ACTION_MEDIA_UNMOUNTED //SD卡卸载
Intent.ACTION_USER_PRESENT//解除锁屏
ConnectivityManager.CONNECTIVITY_ACTION//网络状态变化
[html] view
plaincopy
<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>
[java] view
plaincopy
public class StaticBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Log.d(TAG, "onReceive boot: ");
Intent new_intent = new Intent(context,TestLauncher.class);
//popup the activity
new_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 //时间变化 每分钟一次
[java] view
plaincopy
相关文章推荐
- android模拟器访问localhost或127.0.0.1报错
- android Intent打开各种类型文件((PDF、word、excel、ppt、chm)
- OpenCV4Android 提取特征点描述符(Feature Descriptor)
- Android总结篇系列:Android广播机制
- android ndk 入门之打印log信息
- 第三章:Android之NDK的使用
- android样式设计
- Android使用页面布局操作SQLite数据库
- 生成二维码(中间带logo) android
- Android中的广播Broadcast详解
- Android内核开发:学会分析系统的启动log
- android 电话号码的获取及拨打电话
- Android开发笔记——ScrollView中解决listview,gridview显示不全问题
- Android动画介绍汇总
- Android/Java线程同步
- ADT(android devolopment tools)安装
- android assets文件夹资源的访问
- 关于AndroidResideMenu开源项目的详解
- Android 学习笔记之如何实现简单相机功能
- android的数据存储方式---5种方法