Android 5.1 API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
API 级别:22
Android 5.1 (LOLLIPOP_MR1) 是 Lollipop 版本的更新,为用户和应用开发者提供了新功能。
本文档介绍了最值得注意的新 API。
如需简要了解新平台功能,请参阅 Android Lollipop 亮点。
更新目标 API 级别
如需开始为 Android 5.1 构建应用,请使用 SDK 管理器下载 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
类。
Carrier Services
Android 5.1 支持电信服务提供商创建可在 Android 设备上执行运营商配置任务的应用。这些 API 为运营商开发的应用提供了一种安全且灵活的方式来执行这些任务并通过 Google Play 分发。使用这些函数的应用必须由与设备的通用集成电路卡 (UICC) 中的证书匹配的证书签名。
运营商服务 API 已添加到 TelephonyManager
类、SmsManager
类和新的 CarrierMessagingService
类中。应用可以通过调用 hasCarrierPrivileges()
方法检查对这些 API 的访问权限。未经授权调用这些 API 的应用会收到 SecurityException
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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)."]]