Android 4.0 無法接收開機廣播的問題

來源:互聯網
上載者:User

前面的文章 Android 開機廣播的使用 中已經提到Android的開機啟動,但是在Android 4.0 有時可以接收到開機啟動廣播,有時卻不可以。經過分析發現,如果應用程式安裝上始終沒有被開啟過,那麼在Android啟動時,該應用無法接收到開機啟動廣播android.permission.RECEIVE_BOOT_COMPLETED。

原來在Android 3.1的更新文檔中已經做了說明。

 

原文如下

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.

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.
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)的應用程式。


應用程式處於停止狀態情況有兩種,一種是他們是第一次安裝,但尚未啟動,另一種是在管理應用程式中由使用者手動停止。

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.