2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
データプランの実装
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
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()));
デバイスでは、アプリを使用して、次のいずれかの条件のデータプランのみを設定できます。
最初の 2 つの条件によって出荷前のシステム イメージへの事前インストールが不要となり、携帯通信会社のアプリをユーザーがインストールできるようになります。OS によって設定済みのすべてのデータプランの詳細が保護され、最初に OS に詳細が提供された携帯通信会社のアプリのみが利用できるようになります(CDD の要件)。
推奨される設計としては、携帯通信会社のアプリがアイドル時のメンテナンス サービスを使用してデータプランの詳細を毎日更新する方法などがありますが、携帯通信会社はキャリア内部の SMS メッセージを通じてデータプランの詳細を送信するなど、さまざまな方法を自由に選択できます。アイドル時のメンテナンス サービスは、setRequiresDeviceIdle()
と setRequiresCharging()
を使用する JobScheduler
ジョブで実装するのが最も適しています。
OS によるデータ使用量
OS は、SubscriptionPlan API によって提供されるデータプランの詳細を次のように使用します。
- プランの詳細は、正確なデータ使用量およびアップグレード / アップセル用の携帯通信会社のアプリへの直接ディープリンクで表示するため、設定アプリを通じてユーザーに提示されます。
- データ使用量の警告と制限の通知のしきい値は、プランの詳細に基づいて自動的に設定されます(警告は制限の 90% で表示されるように設定)。
- 携帯通信会社のネットワークが一時的に「混雑している」場合、OS はタイムシフト可能な JobScheduler ジョブを遅延させ、ネットワークの負荷を軽減します。
- 携帯通信会社のネットワークが一時的に「定額制」である場合、携帯通信会社がオーバーライドをクリアするか、タイムアウト値(指定されている場合)に達するまで、OS はモバイル接続を「定額制」として報告します。
- OS は、ユーザーの現在のデータ使用量と全体的なデータの上限を比較することで、請求期間の最後にユーザーの通常のデータ使用量を予測します。また、たとえばアプリにマルチパス データの使用を許可し、余分なデータのうち 10% を慎重に割り当てることによってユーザー エクスペリエンスを改善します。
カスタマイズと検証
Android 設定アプリには、携帯通信会社が設定したすべてのデータプランの詳細が表示され、携帯通信会社に関する最も正確な状態や、プランをアップグレードするアプリへのパスをユーザーが確認できます。設定アプリをカスタマイズしたデバイス メーカーには、こうした詳細の表示を継続するようおすすめします。
上記の SubscriptionManager
API は android.telephony.cts.SubscriptionManagerTest
によってテストされています。そのため確実に、データプランの詳細が携帯通信会社のアプリによって設定され、変更が OS 内に適用されます。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-26 UTC。
[null,null,["最終更新日 2025-03-26 UTC。"],[],[],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."]]