Android之不能静态注册的系统广播(5个)
来源:互联网 发布:数据库视频百度云 编辑:程序博客网 时间:2024/06/05 02:28
在Android开发中,有些系统广播是不能在清单文件中静态注册的,只能通过registerReceiver方法进行动态注册(Android文档这样描述:You cannot receive this through components declared in manifests, only by explicitly registering for it with {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) Context.registerReceiver()}.)
下面是几个常见的只能动态注册的广播:
1、当设备没有进行交互,屏幕关闭发送的广播:
public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
Android官方文档如下定义:
/** * Broadcast Action: Sent when the device goes to sleep and becomes non-interactive. * <p> * For historical reasons, the name of this broadcast action refers to the power * state of the screen but it is actually sent in response to changes in the * overall interactive state of the device. * </p><p> * This broadcast is sent when the device becomes non-interactive which may have * nothing to do with the screen turning off. To determine the * actual state of the screen, use {@link android.view.Display#getState}. * </p><p> * See {@link android.os.PowerManager#isInteractive} for details. * </p> * You <em>cannot</em> receive this through components declared in * manifests, only by explicitly registering for it with * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) * Context.registerReceiver()}. * * <p class="note">This is a protected intent that can only be sent * by the system. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
2、当设备进行互动但屏幕打开可能什么也没做发送的广播:
public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
Android官方文档如下定义:
/** * Broadcast Action: Sent when the device wakes up and becomes interactive. * <p> * For historical reasons, the name of this broadcast action refers to the power * state of the screen but it is actually sent in response to changes in the * overall interactive state of the device. * </p><p> * This broadcast is sent when the device becomes interactive which may have * nothing to do with the screen turning on. To determine the * actual state of the screen, use {@link android.view.Display#getState}. * </p><p> * See {@link android.os.PowerManager#isInteractive} for details. * </p> * You <em>cannot</em> receive this through components declared in * manifests, only by explicitly registering for it with * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) * Context.registerReceiver()}. * * <p class="note">This is a protected intent that can only be sent * by the system. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
3、当前时间已经改变,每分钟发送一次的广播:
public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
Android官方文档如下定义:
/** * Broadcast Action: The current time has changed. Sent every * minute. You <em>cannot</em> receive this through components declared * in manifests, only by explicitly registering for it with * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) * Context.registerReceiver()}. * * <p class="note">This is a protected intent that can only be sent * by the system. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
4、当前设备方向,区域设置等发生了变化。用户界面(视图层次)根据新的信息重建时发送的广播:
public static final String ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
Android官方文档如下定义:
/** * Broadcast Action: The current device {@link android.content.res.Configuration} * (orientation, locale, etc) has changed. When such a change happens, the * UIs (view hierarchy) will need to be rebuilt based on this new * information; for the most part, applications don't need to worry about * this, because the system will take care of stopping and restarting the * application to make sure it sees the new changes. Some system code that * can not be restarted will need to watch for this action and handle it * appropriately. * * <p class="note"> * You <em>cannot</em> receive this through components declared * in manifests, only by explicitly registering for it with * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) * Context.registerReceiver()}. * * <p class="note">This is a protected intent that can only be sent * by the system. * * @see android.content.res.Configuration */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
5、当电池电量发生改变是发送的广播:
public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
Android官方文档如下定义:
/** * Broadcast Action: This is a <em>sticky broadcast</em> containing the * charging state, level, and other information about the battery. * See {@link android.os.BatteryManager} for documentation on the * contents of the Intent. * * <p class="note"> * You <em>cannot</em> receive this through components declared * in manifests, only by explicitly registering for it with * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) * Context.registerReceiver()}. See {@link #ACTION_BATTERY_LOW}, * {@link #ACTION_BATTERY_OKAY}, {@link #ACTION_POWER_CONNECTED}, * and {@link #ACTION_POWER_DISCONNECTED} for distinct battery-related * broadcasts that are sent and can be received through manifest * receivers. * * <p class="note">This is a protected intent that can only be sent * by the system. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
1 0
- Android之不能静态注册的系统广播(5个)
- Android之不能静态注册的系统广播(5个)
- Android 不能静态注册的广播
- Android中不能静态注册的广播
- Android广播之注册广播(包括静态广播和动态广播的注册)源码分析
- 不能静态注册的广播
- Android学习小记----监听电量的变化(不能静态注册的广播)
- 【Android成长之路】全局大喇叭——广播机制的浅谈(接收系统广播与动、静态注册接收器)
- Android进阶之路 - BroadcaseReceiver(自定义广播、有序广播、无序广播、广播拦截、动态注册、静态注册)的详细使用方式
- Android中的静态系统广播与动态系统广播及其相应的注册与接收
- Android之广播二(静态注册实现开机启动)
- Android之广播机制—静态注册
- Android静态注册广播和动态注册广播的区别
- Android 广播BroadcastReceiver静态/动态注册,获取系统电量广播【开机广播】,获取网络状态广播,Timer的使用简介
- android 静态注册广播
- Android 接收系统发送的广播,动态注册和静态注册
- android中广播的使用(动态和静态注册)
- Android广播的静态与动态注册
- C-6.结构体
- Learning ROS for Robotics Programming Second Edition学习笔记(三) 补充 hector_slam
- java 变量创建后在内存中的存储关系+空指针异常机理+图文解释
- FreeRTOS系列第3篇---FreeRTOS移植指南
- Unreal引擎术语表
- Android之不能静态注册的系统广播(5个)
- ""与null区别 空指针异常机理
- 0014.trait的混入
- 0015.scala的多重继承、多重继承构造器执行顺序、基于trait的AOP实现
- 【Leetcode】Binary Tree Inorder Traversal
- 0016.scala中的包
- object-UI之基本控件
- 0017.包、类、对象、成员的访问权限
- 【Leetcode】Populating Next Right Pointers in Each Node