Android之不能静态注册的系统广播(5个)

原创 2015年11月21日 08:39:07

在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";
版权声明:本文为博主原创文章,转载请注明出处

相关文章推荐

Intent用法总结

activities,services, broadcast receivers均是由intent开启的.但是这三种用法不会重叠。在帮助文档中是这样介绍的:·        An Intentobje...

Android之不能静态注册的系统广播(5个)

在Android开发中,有些系统广播是不能在清单文件中静态注册的,只能通过registerReceiver方法进行动态注册(Android文档这样描述:You cannot receive this...

Android静态注册无法接受系统广播问题

概要 引入 google文档 翻译总结 目前提高

Android中不能静态注册的广播

Android中不能静态注册的广播有: android.intent.action.SCREEN_ON android.intent.action.SCREEN_OFF android.inte...

android 静态注册广播

步骤: 1、编写一个类

Android——接收广播(静态注册)

静态注册广播是针对整个手机,只要你安装了此app,它都可以接收到发来的广播,并不是仅仅局限于一个Activity,一个应用内部。静态注册需要将发送方和接收方各自创建一个Android项目:发送方:只需...

Android静态注册广播receiver检测WIFI连接状况变化

 Android静态注册广播receiver检测WIFI连接状况变化 在AndroidManifest.xml静态注册一个receiver,增加对WiFi状态变化时候Android系统发送的广...

Android之广播机制—静态注册

广播机制: 通过当前Activity里加载的布局内的控件绑定监听器,监听器内创建Intent对象, 并给Intent的action标签赋值(一般选择内置标签), 并用当前activity的对象的sen...

Android关于如何取消静态注册的广播事件,你知道吗?

大家都知道,关于Android广播事件的注册
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)