ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ใช้แพ็กเกจอินเทอร์เน็ต
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Android 9 ช่วยให้ผู้ให้บริการสามารถให้รายละเอียดแพ็กเกจที่ถูกต้องแก่ผู้ใช้โดยตรงในแอปการตั้งค่า เพื่อลดความสับสนของผู้ใช้และลดการโทรขอรับการสนับสนุน ในอุปกรณ์ที่ใช้ Android 4.0 ขึ้นไป ผู้ใช้สามารถกำหนดค่ารายละเอียดแพ็กเกจอินเทอร์เน็ตของผู้ให้บริการแต่ละรายด้วยตนเองในแอปการตั้งค่า เช่น การตั้งค่าคำเตือนและขีดจำกัดเพื่อจัดการปริมาณการใช้อินเทอร์เน็ต
การกําหนดค่าตามผู้ให้บริการ
หากต้องการกำหนดค่าแพ็กเกจอินเทอร์เน็ต ผู้ให้บริการสามารถเพิ่มฟังก์ชันการทำงานลงในแอป Android ที่มีอยู่ได้โดยใช้ SubscriptionPlan
API
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 ข้อแรกช่วยให้ผู้ใช้ติดตั้งแอปของผู้ให้บริการได้โดยไม่ต้องติดตั้งแอปดังกล่าวลงในภาพระบบที่โรงงานล่วงหน้า
ระบบปฏิบัติการบังคับใช้ (และ CDD กำหนด) ว่ารายละเอียดแพ็กเกจอินเทอร์เน็ตที่กำหนดค่าไว้ทั้งหมดจะได้รับการปกป้องและพร้อมให้บริการแก่แอปของผู้ให้บริการที่ระบุรายละเอียดให้กับระบบปฏิบัติการตั้งแต่แรกเท่านั้น
การออกแบบที่แนะนำอย่างหนึ่งคือแอปของผู้ให้บริการจะใช้บริการบำรุงรักษาที่ไม่ได้ใช้งานเพื่ออัปเดตรายละเอียดแพ็กเกจอินเทอร์เน็ตทุกวัน แต่ผู้ให้บริการสามารถใช้กลไกได้หลากหลาย เช่น การรับรายละเอียดแพ็กเกจอินเทอร์เน็ตผ่านข้อความ SMS ภายในของผู้ให้บริการ บริการบำรุงรักษาขณะไม่มีการใช้งานเหมาะที่จะใช้กับงาน JobScheduler
ที่ใช้ setRequiresDeviceIdle()
และ setRequiresCharging()
การใช้งานตามระบบปฏิบัติการ
ระบบปฏิบัติการใช้รายละเอียดแพ็กเกจอินเทอร์เน็ตที่ SubscriptionPlan API ระบุไว้ดังนี้
- รายละเอียดแพ็กเกจจะแสดงผ่านแอปการตั้งค่าเพื่อแสดงข้อมูลการใช้งานที่ถูกต้องแก่ผู้ใช้ และเพื่อมอบDeep Link ไปยังแอปของผู้ให้บริการโดยตรงเพื่อโอกาสในการอัปเกรด/ขายอัปเซล
- ระบบจะกำหนดเกณฑ์การแจ้งเตือนขีดจำกัดและคำเตือนการใช้อินเทอร์เน็ตโดยอัตโนมัติตามรายละเอียดแพ็กเกจ โดยตั้งค่าคำเตือนไว้ที่ 90% ของขีดจำกัด
- หากผู้ให้บริการระบุชั่วคราวว่าเครือข่าย"แออัด" ระบบปฏิบัติการจะเลื่อนเวลาของงาน JobScheduler ที่เลื่อนเวลาได้ เพื่อลดภาระในเครือข่ายของผู้ให้บริการ
- หากผู้ให้บริการระบุว่าเครือข่ายเป็น"ไม่จำกัด" ชั่วคราว ระบบปฏิบัติการจะรายงานการเชื่อมต่อมือถือเป็น "ไม่จำกัด" จนกว่าผู้ให้บริการจะล้างการลบล้าง หรือจนกว่าจะถึงค่าการหมดเวลา (หากระบุไว้)
- ระบบปฏิบัติการจะประมาณปริมาณการใช้อินเทอร์เน็ตปกติของผู้ใช้เมื่อสิ้นสุดรอบการเรียกเก็บเงินโดยเปรียบเทียบปริมาณการใช้อินเทอร์เน็ตปัจจุบันของผู้ใช้กับขีดจำกัดอินเทอร์เน็ตโดยรวม และจัดสรรอินเทอร์เน็ตส่วนเกิน 10% เพื่อปรับปรุงประสบการณ์ของผู้ใช้ เช่น โดยการอนุญาตให้แอปใช้อินเทอร์เน็ตหลายเส้นทาง
การปรับแต่งและการตรวจสอบ
แอปการตั้งค่า Android จะแสดงรายละเอียดแพ็กเกจอินเทอร์เน็ตทั้งหมดที่กำหนดค่าโดยผู้ให้บริการเครือข่าย ซึ่งช่วยให้ผู้ใช้เห็นสถานะความสัมพันธ์กับผู้ให้บริการเครือข่ายที่ถูกต้องที่สุด และมอบเส้นทางไปยังแอปของผู้ให้บริการเครือข่ายเพื่อให้ผู้ใช้อัปเกรดแพ็กเกจได้ เราขอแนะนำให้ผู้ผลิตอุปกรณ์ที่เลือกปรับแต่งแอปการตั้งค่าแสดงรายละเอียดเหล่านี้ต่อไป
SubscriptionManager
API ที่อธิบายไว้ในหน้านี้ได้รับการทดสอบโดย android.telephony.cts.SubscriptionManagerTest
ซึ่งช่วยให้มั่นใจได้ว่าแอปของผู้ให้บริการจะกำหนดค่ารายละเอียดแพ็กเกจอินเทอร์เน็ตได้ และการเปลี่ยนแปลงจะเผยแพร่ภายในระบบปฏิบัติการ
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[[["เข้าใจง่าย","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 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."]]