Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發 >> 初階開發

Android 系統廣播 Intent action 對照大全(依 API Level 分類)

編輯:初階開發

在 Android 中註冊 BroadcastReceiver 時,action 字串就是決定「你要收什麼訊息」的關鍵。以下依 API Level 整理各版本新增的系統廣播 action,方便查閱比對。

API Level 3(SDK 1.5)

這是 Android 1.5 的基準清單,共 83 個 action,大致可分成以下幾類。

藍牙(Bluetooth)

android.bluetooth.a2dp.intent.action.SINK_STATE_CHANGED
android.bluetooth.intent.action.BLUETOOTH_STATE_CHANGED
android.bluetooth.intent.action.BOND_STATE_CHANGED_ACTION
android.bluetooth.intent.action.DISCOVERY_COMPLETED
android.bluetooth.intent.action.DISCOVERY_STARTED
android.bluetooth.intent.action.HEADSET_ADUIO_STATE_CHANGED
android.bluetooth.intent.action.HEADSET_STATE_CHANGED
android.bluetooth.intent.action.NAME_CHANGED
android.bluetooth.intent.action.PAIRING_CANCEL
android.bluetooth.intent.action.PAIRING_REQUEST
android.bluetooth.intent.action.REMOTE_DEVICE_CONNECTED
android.bluetooth.intent.action.REMOTE_DEVICE_DISAPPEARED
android.bluetooth.intent.action.REMOTE_DEVICE_DISCONNECTED
android.bluetooth.intent.action.REMOTE_DEVICE_DISCONNECT_REQUESTED
android.bluetooth.intent.action.REMOTE_DEVICE_FOUND
android.bluetooth.intent.action.REMOTE_NAME_FAILED
android.bluetooth.intent.action.REMOTE_NAME_UPDATED
android.bluetooth.intent.action.SCAN_MODE_CHANGED

電源、電池與開關機

android.intent.action.AIRPLANE_MODE
android.intent.action.BATTERY_CHANGED
android.intent.action.BATTERY_LOW
android.intent.action.BOOT_COMPLETED
android.intent.action.REBOOT
android.intent.action.DEVICE_STORAGE_LOW
android.intent.action.DEVICE_STORAGE_OK

螢幕與使用者狀態

android.intent.action.SCREEN_OFF
android.intent.action.SCREEN_ON
android.intent.action.USER_PRESENT
android.intent.action.CAMERA_BUTTON
android.intent.action.CONFIGURATION_CHANGED
android.intent.action.INPUT_METHOD_CHANGED
android.intent.action.WALLPAPER_CHANGED

媒體與外接儲存

android.intent.action.MEDIA_BAD_REMOVAL
android.intent.action.MEDIA_BUTTON
android.intent.action.MEDIA_CHECKING
android.intent.action.MEDIA_EJECT
android.intent.action.MEDIA_MOUNTED
android.intent.action.MEDIA_NOFS
android.intent.action.MEDIA_REMOVED
android.intent.action.MEDIA_SCANNER_FINISHED
android.intent.action.MEDIA_SCANNER_SCAN_FILE
android.intent.action.MEDIA_SCANNER_STARTED
android.intent.action.MEDIA_SHARED
android.intent.action.MEDIA_UNMOUNTABLE
android.intent.action.MEDIA_UNMOUNTED
android.intent.action.UMS_CONNECTED
android.intent.action.UMS_DISCONNECTED
android.media.AUDIO_BECOMING_NOISY
android.media.RINGER_MODE_CHANGED
android.media.VIBRATE_SETTING_CHANGED

套件管理(Package)

android.intent.action.PACKAGE_ADDED
android.intent.action.PACKAGE_CHANGED
android.intent.action.PACKAGE_DATA_CLEARED
android.intent.action.PACKAGE_INSTALL
android.intent.action.PACKAGE_REMOVED
android.intent.action.PACKAGE_REPLACED
android.intent.action.PACKAGE_RESTARTED
android.intent.action.MANAGE_PACKAGE_STORAGE
android.intent.action.UID_REMOVED
android.intent.action.PROVIDER_CHANGED

電話與簡訊

android.intent.action.PHONE_STATE
android.intent.action.NEW_OUTGOING_CALL
android.intent.action.DATA_SMS_RECEIVED
android.provider.Telephony.SIM_FULL
android.provider.Telephony.SMS_RECEIVED
android.provider.Telephony.WAP_PUSH_RECEIVED

網路與 Wi-Fi

android.Net.conn.BACKGROUND_DATA_SETTING_CHANGED
android.net.wifi.NETWORK_IDS_CHANGED
android.net.wifi.RSSI_CHANGED
android.net.wifi.SCAN_RESULTS
android.net.wifi.STATE_CHANGE
android.net.wifi.WIFI_STATE_CHANGED
android.net.wifi.supplicant.CONNECTION_CHANGE
android.net.wifi.supplicant.STATE_CHANGE
android.intent.action.GTALK_CONNECTED
android.intent.action.GTALK_DISCONNECTED

時間、時區與其他

android.intent.action.DATE_CHANGED
android.intent.action.TIMEZONE_CHANGED
android.intent.action.TIME_SET
android.intent.action.TIME_TICK
android.intent.action.HEADSET_PLUG
com.google.gservices.intent.action.GSERVICES_CHANGED

API Level 4(SDK 1.6)新增

android.intent.action.ACTION_POWER_CONNECTED
android.intent.action.ACTION_POWER_DISCONNECTED
android.intent.action.ACTION_SHUTDOWN
android.intent.action.BATTERY_OKAY
android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED
android.speech.tts.engine.TTS_DATA_INSTALLED
com.google.gservices.intent.action.GSERVICES_OVERRIDE

這一版的重點是電源狀態(接上/拔下電源)與 TTS 引擎的資料安裝通知。

API Level 5(SDK 2.0):藍牙 action 全面改版

Android 2.0 對藍牙的 action 命名做了大幅重整,改採 adapter.、device.、headset.、devicepicker. 這種分層結構。舊版(Level 3)的藍牙 action 在此幾乎全部作廢。

android.bluetooth.a2dp.action.SINK_STATE_CHANGED
android.bluetooth.adapter.action.DISCOVERY_FINISHED
android.bluetooth.adapter.action.DISCOVERY_STARTED
android.bluetooth.adapter.action.LOCAL_NAME_CHANGED
android.bluetooth.adapter.action.SCAN_MODE_CHANGED
android.bluetooth.adapter.action.STATE_CHANGED
android.bluetooth.device.action.ACL_CONNECTED
android.bluetooth.device.action.ACL_DISCONNECTED
android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED
android.bluetooth.device.action.BOND_STATE_CHANGED
android.bluetooth.device.action.CLASS_CHANGED
android.bluetooth.device.action.FOUND
android.bluetooth.device.action.NAME_CHANGED
android.bluetooth.devicepicker.action.DEVICE_SELECTED
android.bluetooth.devicepicker.action.LAUNCH
android.bluetooth.headset.action.AUDIO_STATE_CHANGED
android.bluetooth.headset.action.STATE_CHANGED

同時新增兩個非藍牙的 action:

android.intent.action.DOCK_EVENT
android.provider.Telephony.SMS_REJECTED

API Level 6(SDK 2.0.1)

沒有變動。

API Level 7(SDK 2.1)新增

android.intent.action.LOCALE_CHANGED

語言/地區設定變更時發出,適合用來更新已本地化的字串快取。

API Level 8(SDK 2.2)新增

android.app.action.ACTION_PASSWORD_CHANGED
android.app.action.ACTION_PASSWORD_FAILED
android.app.action.ACTION_PASSWORD_SUCCEEDED
android.app.action.DEVICE_ADMIN_DISABLED
android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED
android.app.action.DEVICE_ADMIN_ENABLED
android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE
android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE
android.media.SCO_AUDIO_STATE_CHANGED

這一組主要圍繞裝置管理員(Device Admin)與其密碼策略,另外補上了外接儲存(例如插拔 SD 卡導致應用程式可用/不可用)與藍牙 SCO 音訊通道狀態。

實務提醒

以上清單對應的是 Android 1.5 到 2.2 這個早期階段。後續版本(3.x 以後)新增了大量 action,同時也有部分被標記為 deprecated 或直接移除,例如藍牙相關的 action 又經歷過數次改版。實際開發時請以目前使用的 SDK 官方文件為準。

另外有幾點常踩的坑值得先記住:

  • 靜態註冊(寫在 AndroidManifest.xml 的 intent-filter)無法收到部分 action。最典型的就是 CONNECTIVITY_CHANGE 與 BOOT_COMPLETED 在不同版本上的限制差異,以及 Android 8.0 之後對隱式廣播的收緊。
  • 像 BATTERY_CHANGED 這類 action 只能動態註冊(在程式碼中呼叫 registerReceiver),因為它是有黏性(sticky)的廣播,系統會把最後一筆值留著。
  • 接收敏感廣播(簡訊、來電狀態)需要對應的 READ_SMS、READ_PHONE_STATE 等權限,且在新版 Android 上還必須取得執行期授權。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved