API ของ Android 5.1
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ระดับ API: 22
Android 5.1
(LOLLIPOP_MR1)
เป็นการอัปเดตรุ่น Lollipop ที่มีฟีเจอร์ใหม่ๆ สำหรับผู้ใช้และนักพัฒนาแอป
เอกสารนี้จะแนะนำ API ใหม่ที่โดดเด่นที่สุด
ดูภาพรวมระดับสูงของฟีเจอร์ใหม่ในแพลตฟอร์มได้ที่ไฮไลต์ของ Android Lollipop
อัปเดตระดับ API เป้าหมาย
หากต้องการเริ่มสร้างแอปสำหรับ Android 5.1 ให้ใช้ SDK Manager เพื่อดาวน์โหลดแพลตฟอร์มและภาพระบบ SDK ของ Android 5.1 จากนั้นตั้งค่าโปรเจ็กต์การพัฒนาแอปให้ใช้ targetSdkVersion
ของ "22"
ติดตั้งแอปในภาพระบบ Android 5.1 ทดสอบ แล้วเผยแพร่แอปที่อัปเดตแล้วด้วยการเปลี่ยนแปลงนี้
คุณสามารถใช้ API ของ Android 5.1 ไปพร้อมกับรองรับเวอร์ชันเก่าได้ด้วยการเพิ่มเงื่อนไขลงในโค้ดที่ตรวจสอบระดับ API ของระบบก่อนที่จะเรียกใช้ API ที่ minSdkVersion
ไม่รองรับ ดูข้อมูลเพิ่มเติมเกี่ยวกับการคงความเข้ากันได้แบบย้อนหลังได้ที่การรองรับแพลตฟอร์มเวอร์ชันต่างๆ
ดูข้อมูลเพิ่มเติมเกี่ยวกับวิธีการทำงานของระดับ API ได้ที่ระดับ API คืออะไร
การรองรับซิมการ์ดหลายใบ
Android 5.1 เพิ่มการรองรับการใช้ซิมการ์ดของผู้ให้บริการเครือข่ายมือถือมากกว่า 1 ใบพร้อมกัน ฟีเจอร์นี้ช่วยให้ผู้ใช้เปิดใช้งานและใช้ซิมเพิ่มเติมในอุปกรณ์ที่มีช่องเสียบการ์ดซิมตั้งแต่ 2 ช่องขึ้นไปได้
คุณสามารถเข้าถึงข้อมูลเกี่ยวกับซิมที่ใช้งานอยู่ในปัจจุบันผ่านคลาส SubscriptionManager
รวมถึงดูได้ว่าระบบถือว่าอุปกรณ์กำลังโรมมิงในเครือข่ายปัจจุบันหรือไม่ ข้อมูลนี้มีประโยชน์สำหรับนักพัฒนาแอปที่ต้องการจำกัดหรือปิดการเข้าถึงข้อมูลของแอปสำหรับผู้ใช้อุปกรณ์ที่คำนึงถึงค่าใช้จ่ายในการเข้าถึงข้อมูล แอปสามารถรับการแจ้งเตือนเกี่ยวกับการเปลี่ยนแปลงในการเชื่อมต่อเครือข่ายปัจจุบันของอุปกรณ์ได้ด้วยการขอสิทธิ์ READ_PHONE_STATE
และการตั้งค่า SubscriptionManager.OnSubscriptionsChangedListener
ในออบเจ็กต์ SubscriptionManager
คลาส HTTP ที่เลิกใช้งานแล้ว
คลาส org.apache.http
และคลาส android.net.http.AndroidHttpClient
เลิกใช้งานแล้วใน Android 5.1 คลาสเหล่านี้ไม่มีการดูแลรักษาอีกต่อไป และคุณควรย้ายข้อมูลโค้ดแอปที่ใช้ API เหล่านี้ไปยังคลาส URLConnection
โดยเร็วที่สุด
บริการของผู้ให้บริการ
Android 5.1 รองรับผู้ให้บริการโทรคมนาคมในการสร้างแอปที่ทํางานจัดสรรผู้ให้บริการเครือข่ายในอุปกรณ์ Android ได้ API เหล่านี้เป็นวิธีที่ปลอดภัยและยืดหยุ่นสำหรับแอปที่พัฒนาโดยผู้ให้บริการในการดำเนินการเหล่านี้และเผยแพร่ผ่าน Google Play แอปที่ใช้ฟังก์ชันเหล่านี้ต้องได้รับการรับรองโดยใบรับรองที่ตรงกับใบรับรองใน Universal Integrated Circuit Card (UICC) ของอุปกรณ์
เราได้เพิ่ม Carrier Service API ลงในคลาส TelephonyManager
, คลาส SmsManager
และคลาส CarrierMessagingService
ใหม่ แอปจะตรวจสอบสิทธิ์เข้าถึง API เหล่านี้ได้ด้วยการเรียกใช้เมธอด hasCarrierPrivileges()
แอปที่เรียกใช้ API เหล่านี้โดยไม่ได้รับสิทธิ์เข้าถึงจะได้รับ SecurityException
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 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-27 UTC"],[],[],null,["# Android 5.1 APIs\n\nAPI Level: 22\n\n\nAndroid 5.1\n([LOLLIPOP_MR1](/reference/android/os/Build.VERSION_CODES#LOLLIPOP_MR1))\nis an update to the Lollipop release that offers new features for users and app developers.\nThis document provides an introduction to the most notable new APIs.\n\n\nFor a high-level look at the new platform features, see the [Android Lollipop highlights](/about/versions/lollipop).\n\n### Update your target API level\n\n\nTo start building apps for Android 5.1, use the\n[SDK Manager](/tools/help/sdk-manager) to download the Android 5.1 SDK\nPlatform and System Images. Then set your app development project to use a\n[`targetSdkVersion`](/guide/topics/manifest/uses-sdk-element#target)\nof `\"22\"`. Install your app on an Android 5.1\nsystem image, test it, then publish the updated app with this change.\n\n\nYou can use Android 5.1 APIs while also supporting older versions by adding\nconditions to your code that check for the system API level before executing APIs not supported\nby your [`minSdkVersion`](/guide/topics/manifest/uses-sdk-element#min). To learn more about maintaining backward compatibility, read [Supporting Different Platform\nVersions](/training/basics/supporting-devices/platforms).\n\n\nFor more information about how API levels work, read [What is API Level?](/guide/topics/manifest/uses-sdk-element#ApiLevels)\n\nMultiple SIM Card Support\n-------------------------\n\n\nAndroid 5.1 adds support for using more than one cellular carrier SIM card at a time. This\nfeature lets users activate and use additional SIMs on devices that have two or more SIM card\nslots.\n\n\nYou can access information about the currently active SIM through the [SubscriptionManager](/reference/android/telephony/SubscriptionManager) class, including whether or not the device is considered\nto be roaming on the current network. This information is useful for developers who want to\nthrottle their apps' data access down or off for device users who are sensitive to data access\ncharges. Your app can be alerted to changes in a device's current network connection by\nrequesting the [READ_PHONE_STATE](/reference/android/Manifest.permission#READ_PHONE_STATE) permission and setting [SubscriptionManager.OnSubscriptionsChangedListener](/reference/android/telephony/SubscriptionManager.OnSubscriptionsChangedListener) on the [SubscriptionManager](/reference/android/telephony/SubscriptionManager) object.\n\nDeprecated HTTP Classes\n-----------------------\n\n\nThe `org.apache.http` classes and the `android.net.http.AndroidHttpClient` class\nhave been deprecated in Android 5.1. These classes are no longer being maintained and you should\nmigrate any app code using these APIs to the [URLConnection](/reference/java/net/URLConnection) classes as soon as\npossible.\n\nCarrier Services\n----------------\n\n\nAndroid 5.1 provides support for telecommunication service providers to create apps that can\nperform carrier provisioning tasks on an Android device. These APIs provide a secure and flexible\nway for carrier-developed apps to perform these tasks and be distributed through Google Play. Apps\nthat use these functions must be signed by a certificate that matches the certificate in the\ndevice's Universal Integrated Circuit Card (UICC).\n\n\nThe carrier service APIs have been added to the [TelephonyManager](/reference/android/telephony/TelephonyManager) class,\nthe [SmsManager](/reference/android/telephony/SmsManager) class, and the new [CarrierMessagingService](/reference/android/service/carrier/CarrierMessagingService) class. Apps can check for access to these APIs\nby calling the [hasCarrierPrivileges()](/reference/android/telephony/TelephonyManager#hasCarrierPrivileges()) method. Apps that\ncall these APIs without access receive a [SecurityException](/reference/java/lang/SecurityException)."]]