為配合主幹穩定開發模型,並確保生態系統的平台穩定性,我們將於 2026 年起,在第 2 季和第 4 季將原始碼發布至 AOSP。如要建構及貢獻 AOSP,建議使用 android-latest-release,而非 aosp-main。android-latest-release 資訊清單分支版本一律會參照推送至 AOSP 的最新版本。詳情請參閱「Android 開放原始碼計畫變更」一文。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
外部時間偵測
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
從 Android 12 開始,Android 可以選擇性地使用外部時間來源,向 Time Detector 服務建議 Unix 紀元時間。AOSP 預設不會啟用這項功能。
外部時間來源可讓您向 Android 提供完全自訂的時間建議。收到外部時間來源的建議後,time_detector 服務會根據設定的自動時間優先順序規則,決定是否更新系統時鐘。
實作
如要支援外部時間偵測,您必須實作一個元件,透過系統 API 呼叫將外部時間建議提交至 time_detector 服務。
如要設定外部來源,請使用 core/res/res/values/config.xml 系統伺服器設定檔。將 external 值新增至 config_autoTimeSourcesPriority。
以下範例會告知 Android 在設定系統時鐘時,將外部時間建議設為最高優先順序。如果沒有可用的有效外部時間建議,系統會使用下一個來源 (本例中為 gnss):
<string-array name="config_autoTimeSourcesPriority">
<item>external</item>
<item>gnss</item>
</string-array>
如要向系統提供外部時間建議,請使用 TimeManager 中的 suggestExternalTime 方法。如果使用設定檔中的 config_autoTimeSourcesPriority 設定外部來源,且沒有優先順序較高的時間建議,Android 會使用傳遞至這個方法的時間戳記,設定目前的 Unix Epoch 時間。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-12-03 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-12-03 (世界標準時間)。"],[],[]]