你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2013-04-19] 来源:  作者: [字体: ]

前面的文章 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)的应用程序。


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

 

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

 

 

本文出自 Ray-Ray的博客

 

文章地址 http://www.cnblogs.com/rayray/archive/2013/02/23/2923357.html

 

感谢大家的推荐和收藏

 






收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻