Android 5.1 API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
API 級別:22
Android 5.1 (LOLLIPOP_MR1) 是 Lollipop 版本的更新,可為使用者和應用程式開發人員提供新功能。本文件將介紹最值得注意的新 API。
如要概略瞭解新平台功能,請參閱 Android Lollipop 重點。
更新目標 API 級別
如要開始建構 Android 5.1 應用程式,請使用 SDK Manager 下載 Android 5.1 SDK 平台和系統映像檔。接著,請設定應用程式開發專案,以便使用 "22"
的 targetSdkVersion
。請在 Android 5.1 系統映像檔上安裝應用程式並進行測試,然後發布含有此變更的更新版應用程式。
您可以使用 Android 5.1 API,同時支援舊版,方法是在程式碼中新增條件,在執行 minSdkVersion
不支援的 API 前,先檢查系統 API 級別。如要進一步瞭解如何維持向下相容性,請參閱「支援不同的平台版本」。
如要進一步瞭解 API 級別的運作方式,請參閱「什麼是 API 級別?」。
支援多個 SIM 卡
Android 5.1 新增了一次使用多張電信業者 SIM 卡的支援功能。這項功能可讓使用者在有兩個或更多 SIM 卡插槽的裝置上啟用及使用其他 SIM 卡。
您可以透過 SubscriptionManager
類別存取目前有效 SIM 卡的相關資訊,包括裝置是否在目前網路上漫遊。對於想針對對資料存取費用敏感的裝置使用者,降低或關閉應用程式資料存取權的開發人員來說,這項資訊非常實用。應用程式可以要求 READ_PHONE_STATE
權限,並在 SubscriptionManager
物件上設定 SubscriptionManager.OnSubscriptionsChangedListener
,以便在裝置的目前網路連線發生變更時收到通知。
已淘汰的 HTTP 類別
org.apache.http
類別和 android.net.http.AndroidHttpClient
類別已在 Android 5.1 中淘汰。這些類別已不再維護,您應盡快將使用這些 API 的任何應用程式程式碼遷移至 URLConnection
類別。
電信業者服務
Android 5.1 提供電信服務供應商所需的支援,讓他們建立可在 Android 裝置上執行電信業者佈建任務的應用程式。這些 API 可讓電信業者開發的應用程式以安全且彈性的方式執行這些工作,並透過 Google Play 發行。使用這些函式的應用程式必須由與裝置通用整合電路卡 (UICC) 中的憑證相符的憑證簽署。
電信服務 API 已新增至 TelephonyManager
類別、SmsManager
類別和新的 CarrierMessagingService
類別。應用程式可以透過呼叫 hasCarrierPrivileges()
方法,檢查是否有權存取這些 API。未經授權就呼叫這些 API 的應用程式會收到 SecurityException
。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],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)."]]