zoukankan      html  css  js  c++  java
  • 【Android】Android 4.0 无法接收开机广播的问题

    【Android】Android 4.0 无法接收开机广播的问题

     

    前面的文章 Android 开机广播的使用 中 已经提到Android的开机启动,但是在Android 4.0 有时可以接收到开机启动广播,有时却不可以。经过分析发现,如果应用程序安装上始终没有被打开过,那么在Android启动时,该应用无法接收到开机启动 广播android.permission.RECEIVE_BOOT_COMPLETED。

    原来在Android 3.1的更新文档中已经做了说明。

    下面是引自Android官方API说明,地址 http://developer.android.com/about/versions/android-3.1.html#launchcontrols

    原文如下

    Launch controls on stopped applications

    Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications.

    Note that an application's stopped state is not the same as an Activity's stopped state. The system manages those two stopped states separately.

    The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.

    When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.

    Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding theFLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.

    Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).

    翻译如下

    从Android 3.1开始,系统的软件包管理器跟踪处于停止状态(stopped state)的应用程序,提供了一种控制其启动后台进程和其他应用程序方式。

    需要注意的是应用程序的停止状态(stopped state)和Activity的停止状态是不一样的。该系统可以分别管理这两种停止状态。

    该平台定义了两个新的Intent的Flag,让发送者指定的意图是否应该被允许激活停止的应用程序的组件。

    FLAG_INCLUDE_STOPPED_PACKAGES - Include intent filters of stopped applications in the list of potential targets to resolve against.包括停止的应用程序列表中的。
    FLAG_EXCLUDE_STOPPED_PACKAGES - Exclude intent filters of stopped applications from the list of potential targets.排除停止的应用程序列表中的。

    当两个Flag都不设置或都设置的时候,默认操作是FLAG_INCLUDE_STOPPED_PACKAGES。

    请注意,系统向所有的Intent的广播添加了FL​​AG_EXCLUDE_STOPPED_PACKAGES标志。它这样做是为了防止广播无意中的或 不必要地开启组件的stoppped应用程序的后台服务。后台服务或应用程序可以通过向广播Intent添加 FLAG_INCLUDE_STOPPED_PACKAGES标志来唤醒处于停止状态(stopped state)的应用程序。


    应用程序处于停止状态情况有两种,一种是他们是第一次安装,但尚未启动,另一种是在管理应用程序中由用户手动停止。

     

    简单的说,就是防止开机启动恶意程序,优化启动。经过验证发现,系统级的应用程序是可以接收到开机启动广播的。

     

    转自 http://blog.csdn.net/leilu2008/article/details/8933869

    life is a jounery,yes
  • 相关阅读:
    Activemq安装
    Python小代码_12_生成前 n 行杨辉三角
    Python小代码_11_生成小于 n 的裴波那契数列
    Python小代码_10_判断是否为素数
    Python小代码_9_求水仙花数
    Python小代码_8_今天是今年的第几天
    Python小代码_7_字符串的字符次数统计
    Python小代码_6_列表推导式求 100 以内的所有素数
    Python小代码_5_二维矩阵转置
    关于列表元素的删除
  • 原文地址:https://www.cnblogs.com/CaptainLin/p/3619533.html
Copyright © 2011-2022 走看看