自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
應用程式背景行為追蹤程式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 13 引入了耗電量追蹤器的概念,這是一項監控應用程式前景或背景電池用量的程序,可用於判斷應用程式是否違反某些政策。Android 13 包含兩個耗電量追蹤器:前景服務追蹤器和背景電池用量追蹤器。與其使用自有機制來判斷應用程式是否耗電過度,建議您使用這些追蹤器來監控並提醒使用者電池用量過高。
前景服務追蹤器
前景服務可以執行並長時間使用電池。當前景服務已執行一段長時間但無法顯示時,前景服務追蹤器會向使用者顯示通知,例如使用者已關閉服務的通知。如果使用者點選通知,系統會顯示工作管理員,讓使用者停止前景服務。這個追蹤器預設為啟用。
背景耗電量追蹤器
應用程式可能會在背景耗用電量,而使用者並不知情。背景電池追蹤程式會監控每個應用程式的電池用量。在此情況下,電池用量是由三個維度定義:頂端的前景應用程式、執行不顯示內容的前景服務,以及應用程式的背景部分。如果應用程式的背景電池用量超過某個門檻,應用程式就會移至受限區塊,每天只能執行一個工作。這個追蹤器預設為停用。如要啟用這個追蹤器,請執行下列指令:
adb shell device_config put activity_manager bg_auto_restrict_abusive_apps 1
adb shell device_config put activity_manager bg_current_drain_auto_restrict_abusive_apps_enabled 1
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# App background behavior trackers\n\nAndroid 13 introduces the concept of a\n*power consumption tracker*, which is a process that monitors foreground or\nbackground battery usage by apps to determine if apps violate some policy.\nAndroid 13 contains two power consumption trackers:\nthe foreground service tracker and background battery usage tracker. As opposed\nto using your own mechanisms to determine battery abuse by apps, we\nrecommend using these trackers to monitor and alert users of excessive battery\nusage.\n\nForeground service tracker\n--------------------------\n\nForeground services can execute and use battery for an extended period of time.\nThe foreground service tracker displays a notification to users when a\nforeground service has been running for a long period of time but is invisible,\nsuch as when a user has dismissed the service's notification. If the user\nclicks the notification, the task manager is displayed and lets\nthe user stop the foreground service. This tracker is enabled by default.\n\nBackground battery usage tracker\n--------------------------------\n\nApps can drain battery in the background without the user being aware. The\nbackground battery tracker watches battery usage for each app. Battery usage\nin this context is defined by three dimensions: foreground app on top,\nforeground service running something that isn't visible, and background part of\napp. If the background portion of the app's battery usage crosses some threshold,\nthe app is moved into a restricted bucket limiting it to one job per day. This\ntracker is disabled by default. To enable this tracker, run the following\ncommands: \n\n adb shell device_config put activity_manager bg_auto_restrict_abusive_apps 1\n adb shell device_config put activity_manager bg_current_drain_auto_restrict_abusive_apps_enabled 1"]]