自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
導入資料企劃書
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 9 可讓電信業者直接在「設定」應用程式中向使用者提供可靠的方案詳細資料,以減少使用者疑惑和支援電話。在搭載 Android 4.0 以上版本的裝置上,使用者可以在「設定」應用程式中手動設定特定電信業者的數據方案詳細資料,例如設定警告和限制來管理數據用量。
電信業者設定
如要設定數據方案,電信業者可以使用 SubscriptionPlan
API,為現有的 Android 應用程式新增功能。這些 API 旨在支援多種資料方案類型,包括週期性和非週期性方案,以及隨著時間變更的方案。
以下範例說明如何設定每月重複的常見資料方案:
SubscriptionManager sm =
context.getSystemService(SubscriptionManager.class);
sm.setSubscriptionPlans(subId, Lists.newArrayList(
SubscriptionPlan.Builder.createRecurringMonthly(
ZonedDateTime.parse("2016-12-03T10:00:00Z"))
.setTitle("G-Mobile")
.setDataLimit(4_000_000_000L,
SubscriptionPlan.LIMIT_BEHAVIOR_BILLED)
.setDataUsage(200_493_293L, dataUsageTimestamp)
.build()));
裝置只會在下列任一情況下,允許應用程式設定數據方案:
前兩個條件可讓使用者安裝電信業者應用程式,而不需要在工廠預先安裝到系統映像檔。作業系統會強制執行 (並且符合 CDD 規定),保護所有已設定的資料方案詳細資料,並且只提供給最初向作業系統提供詳細資料的電信業者應用程式。
建議的設計之一是,電信業者應用程式可使用閒置維護服務,每天更新數據方案詳細資料,但電信業者可自由使用各種機制,例如透過電信業者內部簡訊接收數據方案詳細資料。閒置維護服務最好透過使用 setRequiresDeviceIdle()
和 setRequiresCharging()
的 JobScheduler
工作來實作。
使用情形 (依作業系統劃分)
作業系統會以以下方式使用 SubscriptionPlan API 提供的資料方案詳細資料:
- 我們會透過「設定」應用程式顯示方案詳細資料,向使用者顯示正確的資料用量,並提供直接連結至電信業者應用程式的深層連結,提供升級/加購機會。
- 系統會根據方案詳細資料自動設定數據用量警告和限制通知門檻,警告值設為限制的 90%。
- 如果電信業者暫時指出網路「壅塞」,作業系統會延遲可時間調整的 JobScheduler 工作,以減少電信業者網路上的負載。
- 如果電信業者暫時指出網路為「不計量」,作業系統會將行動網路連線回報為「不計量」,直到電信業者清除覆寫值,或達到逾時值 (如有提供) 為止。
- 透過比較使用者目前的資料用量與整體資料限制,OS 會預估使用者在結帳週期結束時的正常資料用量,並保守地分配任何多餘資料的 10%,以改善使用者體驗,例如讓應用程式使用多路徑資料。
自訂和驗證
Android 設定應用程式會顯示所有電信業者設定的數據方案詳細資料,確保使用者能看到最準確的電信業者關係狀態,並提供使用者前往電信業者應用程式升級方案的途徑。建議選擇自訂「設定」應用程式的裝置製造商繼續顯示這些詳細資料。
本頁所述的 SubscriptionManager
API 已由 android.telephony.cts.SubscriptionManagerTest
測試,可確保資料方案詳細資料可由電信業者應用程式設定,且變更會在作業系統中傳播。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","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-07-26 (世界標準時間)。"],[],[],null,["# Implement data plans\n\nAndroid 9 lets carriers directly provide authoritative\nplan details to users in the Settings app to reduce user confusion and support\ncalls. On devices running Android 4.0 and higher, users are able to manually\nconfigure their carrier-specific data plan details in the Settings app, for\nexample, setting warnings and limits to manage their data usage.\n\nConfiguration by carrier\n------------------------\n\nTo configure data plans, carriers can add functionality to their existing\nAndroid apps using the\n[`SubscriptionPlan` APIs](https://developer.android.com/reference/android/telephony/SubscriptionPlan.Builder).\nThe APIs are designed to support a wide range of data plan types, including both\nrecurring and non-recurring plans, and plans that change over time.\n\nHere's an example of how to configure a common type of data plan that recurs\nmonthly: \n\n SubscriptionManager sm =\n context.getSystemService(SubscriptionManager.class);\n sm.setSubscriptionPlans(subId, Lists.newArrayList(\n SubscriptionPlan.Builder.createRecurringMonthly(\n ZonedDateTime.parse(\"2016-12-03T10:00:00Z\"))\n .setTitle(\"G-Mobile\")\n .setDataLimit(4_000_000_000L,\n SubscriptionPlan.LIMIT_BEHAVIOR_BILLED)\n .setDataUsage(200_493_293L, dataUsageTimestamp)\n .build()));\n\nThe device only lets an app configure data plans under one of these conditions:\n\n- The SIM card has explicitly defined an app that can manage it, as defined by [`SubscriptionManager.canManageSubscription()`](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#canManageSubscription(android.telephony.SubscriptionInfo)).\n- The carrier has pushed the [`KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING`](https://developer.android.com/reference/android/telephony/CarrierConfigManager#KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING) value via `CarrierConfigManager` to indicate which app can manage the carrier's data plans.\n- The device has an app built into the system image that has the `MANAGE_SUBSCRIPTION_PLANS` permission.\n\nThe first two conditions enable the carrier app to be installed by the user,\nwithout requiring that it be pre-installed into the system image at the factory.\nThe OS enforces (and the CDD requires) that all configured data plan details are\nprotected and are only made available to the carrier app that originally\nprovided the details to the OS.\n\nOne suggested design is for a carrier app to use an idle maintenance service to\nupdate data plan details on a daily basis, but carriers are free to use a wide\nrange of mechanisms, such as receiving data plan details through carrier-internal\nSMS messages. Idle maintenance services are best implemented with a\n`JobScheduler` job that uses\n[`setRequiresDeviceIdle()`](https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean))\nand\n[`setRequiresCharging()`](https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiresCharging(boolean)).\n\nUsage by OS\n-----------\n\nThe OS uses the data plan details provided by the SubscriptionPlan APIs in the\nfollowing ways:\n\n- The plan details are surfaced via the Settings app to display accurate data usage to users and to provide [direct deep links into the carrier app](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#ACTION_MANAGE_SUBSCRIPTION_PLANS) for upgrade/upsell opportunities.\n- The data usage warning and limit notification thresholds are automatically configured based on the plan details; the warning is set to 90% of the limit.\n- If the carrier temporarily indicates the network is [\"congested\"](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#setSubscriptionOverrideCongested(int,%20boolean,%20long)), the OS delays JobScheduler jobs that can be time-shifted, reducing the load on the carrier network.\n- If the carrier temporarily indicates the network is [\"unmetered\"](https://developer.android.com/reference/android/telephony/SubscriptionManager#setSubscriptionOverrideUnmetered(int,%20boolean,%20long)), the OS can report the cellular connection as \"unmetered\" until the carrier clears the override, or until the timeout value (if provided) is reached.\n- By comparing the user's current data usage with the overall data limit, the OS estimates the user's normal data usage at the end of the billing cycle and conservatively allocates 10% of any surplus data to improve the user experience, for example, by letting apps use multi-path data.\n\nCustomization and validation\n----------------------------\n\nThe Android Settings app displays all carrier-configured data plan details,\nensuring that users see the most accurate status of their carrier relationship,\nand offering users a path into the carrier app to upgrade their plan. Device\nmanufacturers choosing to customize the Settings app are recommended to continue\nsurfacing these details.\n\nThe `SubscriptionManager` APIs described on this page are tested by\n`android.telephony.cts.SubscriptionManagerTest`, which ensures that data plan\ndetails can be configured by carrier apps and that changes are propagated within\nthe OS."]]