Android 13(API 33)
It was 2022年8月15日
officially released on (the release time was earlier than in previous years), and the source code of the official release was also pushed to the AOSP Android open source project on the same day.
As of the writing of this article, some domestic application software developers have gradually received new version adaptation requirements from mobile phone manufacturers (Huami OV, etc.). Currently, for Android application developers, the compatibility and adaptation of Android 13 software needs to be put on the work schedule.
In order to fit the title of this article, this article combines the official Android Developer documentation to elaborate on two aspects Android13适配点
.Android13新特性
Adaptation point:
- Subdivide media permissions:
READ_EXTERNAL_STORAGE
Subdivide into IAMGES, VIDEO, AUDIO permissions
(若设置 targetSdk>=33 则此项必需适配!
) - WebView adjustment: obsolete
setAppCacheEnabled
andsetForceDark
method;
(若设置 targetSdk>=33 则此项必需适配!
) - Static broadcast registration:
静态广播
when registering, you need to set对其他应用的可见性
(若设置 targetSdk>=33 则此项必需适配!
) - Notification permission: New runtime notification permission:
POST_NOTIFICATIONS
(若设置 targetSdk>=33 则此项必需适配!
) - Wi-Fi: Added
NEARBY_WIFI_DEVICES
runtime permissions
(若设置 targetSdk>=33 则此项必需适配!
) - Body sensor background permissions: add
BODY_SENSORS_BACKGROUND
runtime permissions
(若设置 targetSdk>=33 则此项必需适配!
) - Clipboard content hidden:
新增内容隐藏API
(根据业务需求,选择性适配!
) - Restrictions for non-SDK interfaces
(若设置 targetSdk>=33 则此项必需适配!
)
New features:
- Foreground Service Manager: Added to the system
前台服务管理器
(系统新特性无需适配!
)
1. Segmentation of media rights
Starting from Android 13, 以Android13(API 33+)为目标平台的应用
, system 新增
runtime permissions READ_MEDIA_IAMGES
, READ_MEDIA_VIDEO
, READ_MEDIA_AUDIO
替代
original READ_EXTERNAL_STORAGE
permissions.
permissions | Permission Description |
---|---|
READ_MEDIA_IAMGES | Image permissions |
READ_MEDIA_VIDEO | video rights |
READ_MEDIA_AUDIO | audio permissions |
When the app is upgraded to targetSdk>=33
:
- Application of authorized
READ_EXTERNAL_STORAGE
permissions: The system will automatically grant corresponding fine-grained permissions. - Permissions are still requested without authorization
READ_EXTERNAL_STORAGE
: the pro-test system will not grant any permissions.
Subdivided media permission dynamic application pop-up window style:
- If the
READ_MEDIA_IMAGES
andREAD_MEDIA_VIDEO
permissions are requested at the same time, the system will prompt the following permission pop-up window:
- If
READ_MEDIA_AUDIO
permission , the system will prompt the following pop-up window:
Official reference:
Android Developer Subdivided Media Permissions:
https://developer.android.google.cn/about/versions/13/behavior-changes-13
Two, WebView
Starting from Android 13, 以Android13(API 33+)为目标平台的应用
WebView has the following methods and API adjustments:
WebSettings.setAppCacheEnabled()
method废弃
.WebSettings.setForceDark()
method废弃
.
2.1 setAppCacheEnabled Obsolete
WebView 95+ version is no longer supportedsetAppCacheEnabled
Chrome version 85+ is no longer supportedAppCache
2.2 setForceDark obsolete
Starting from Android 13 以Android13(API 33+)为目标平台的应用
, the system will automatically set the light or dark theme style of WebView according to the theme attribute isLightTheme of the application (the system will set prefers-color-scheme according to isLightTheme). At the same time, the API methods related to setting the theme style of the developer's Webview WebSettings.setForceDark()
will be discarded.
Based on above changes:
- If developers still need to customize the theme color of Webview, they can use the :
WebSettings.setAlgorithmicDarkeningAllowed()
orWebSettingsCompat.setAlgorithmicDarkeningAllowed()
method. - If the developer still uses
WebSettings.setForceDark()
the system, an error will be displayed:
W/cr_WebSettings: setForceDark() is a no-op in an app with targetSdkVersion>=T
Official reference:
Android Developer static broadcast registration official introduction:
https://developer.android.google.cn/about/versions/13/behavior-changes-13
3. Static broadcast registration
Starting from Android 13, when 以Android13(API 33+)为目标平台的应用
registering 静态广播
, you need to set 对其他应用的可见性
:
若对其他应用可见
, set when broadcasting registration:Context.RECEIVER_EXPORTED
若仅应用内使用
, set when broadcasting registration:Context.RECEIVER_NOT_EXPORTED
private void registerTestReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction("com.xiaxl.test.action");
// api >= 33
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// 跨应用间使用
MainActivity.this.registerReceiver(mTestReceiver, filter, Context.RECEIVER_EXPORTED);
// 应用内使用
//MainActivity.this.registerReceiver(mTestReceiver, filter, Context.RECEIVER_EXPORTED);
}
// api <= 32
else {
MainActivity.this.registerReceiver(mTestReceiver, filter);
}
}
Official reference:
Android Developer static broadcast registration official introduction:
https://developer.android.google.cn/about/versions/13/features#java
4. Notification authority
Android 13 introduces a new runtime notification permission: POST_NOTIFICATIONS
.
POST_NOTIFICATIONS
The permission level is defined as dangerous
the developer needs to use this permission 动态申请
, waiting for the user to actively authorize:
- For
Android13(API 33+)为目标平台的应用
:
When displaying the Android notification bar, on the one hand, it needs to be declared in the AndroidManifestandroid.permission.POST_NOTIFICATION
, and on the other hand, the code needs to dynamically apply for the permission of the notification bar.
<!-- AndroidManifest权限声明 -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xiaxl.test">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</manifest>
// Java代码动态申请POST_NOTIFICATIONS权限
if (Build.VERSION.SDK_INT >= 33) {
int checkPermission =
ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.POST_NOTIFICATIONS);
if (checkPermission != PackageManager.PERMISSION_GRANTED) {
//动态申请
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
Manifest.permission.POST_NOTIFICATIONS}, PERMISSION_REQUEST_CODE);
} else {
//showRecordNotification();
}
} else {
//showRecordNotification();
}
POST_NOTIFICATIONS 动态授权申请弹窗
as shown below:
- For the target platform
Android12(API 32-)为目标平台的应用
: when running on Android 13 and above devices, when .API 32-
应用第一次显示通知时,系统会自动弹出以下提示框,要求用户动态授权
Official reference:
Android Developer notification runtime permission official introduction:
https://developer.android.google.cn/guide/topics/ui/notifiers/notification-permission
5. Wi-Fi permissions
Starting from Android 13, the Android system has added the NEARBY_WIFI_DEVICES permission to distinguish the original permissionACCESS_FINE_LOCATION
from (to avoid the need to request the user's location permission when the developer uses the Wi-Fi capability earlier, which causes ambiguity for the user).Wi-Fi能力使用
Starting from Android 13, developers no longer 不通过Wi-Fi推导用户的物理位置
need to request ACCESS_FINE_LOCATION
permissions . At the same time, the official summarizes NEARBY_WIFI_DEVICES
the following usage scenarios for new permissions:
官方参考:
Android Developer NEARBY_WIFI_DEVICES:
https://developer.android.google.cn/reference/android/Manifest.permission#NEARBY_WIFI_DEVICES
Six, clipboard content hidden
Starting from Android 13 (API 33), a new item has been added to the Android clipboard 新API
:
Starting from Android 13 (API 33), users can choose to use the API PersistableBundle#(ClipDescription.EXTRA_IS_SENSITIVE, true)
to hide sensitive information about user accounts and passwords to be copied to the clipboard.
Examples of related API usage are as follows:
private void addData2Clipboard() {
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("111111", "我是密码");
ClipDescription description = clipData.getDescription();
// 隐私内容:剪切板加密
PersistableBundle persistableBundle = new PersistableBundle();
if (Build.VERSION.SDK_INT >= 33) {
persistableBundle.putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true);
} else {
persistableBundle.putBoolean("android.content.extra.IS_SENSITIVE", true);
}
description.setExtras(persistableBundle);
// 剪切板添加加密内容
clipboardManager.setPrimaryClip(clipData);
}
不使用新API
Compared with 使用新API
hiding sensitive information, the comparison before and after the clipboard is as follows:
Seven, body sensor background permissions
Starting from Android 13, 以Android13(API 33+)为目标平台的应用
when 后台
accessing 身体传感器
(such as heart rate, body temperature, and blood oxygen saturation), in addition to requesting the existing BODY_SENSORS
permissions , you also need to request BODY_SENSORS_BACKGROUND
permissions.
官方参考:
Android Developer BODY_SENSORS_BACKGROUND:
https://developer.android.google.cn/reference/android/Manifest.permission#BODY_SENSORS_BACKGROUND
8. Non-SDK interface restrictions
Starting from Android 9 (API level 28), the official has gradually implemented restrictions on the non-SDK interfaces used by applications.
These restrictions come into play if your app passes references 非 SDK 接口
or tries 使用反射或 JNI 来获取句柄
. The official explanation given is for 提升用户体验、降低应用崩溃风险
.
8.1. Non-SDK interface detection tool
The official gives a detection tool, download address: veridex
https://android.googlesource.com/platform/prebuilts/runtime/+archive/master/appcompat.tar.gz
How to use veridex:
appcompat.sh --dex-file=apk.apk
8.2、blacklist、greylist、greylist-max-o、greylist-max-p含义
In the above screenshot, the meanings of blacklist, greylist, greylist-max-o, and greylist-max-p are as follows:
- blacklist Blacklist: Prohibited non-SDK interfaces, crash directly at runtime (so must be resolved)
- greylist greylist: the non-SDK interface that can still be used in the current version, but may become a restricted non-SDK interface in the next version
- greylist-max-o: A non-SDK interface that can be used in targetSDK<=O, but is prohibited in targetSDK>=P
- greylist-max-p: non-SDK interfaces that can be used in targetSDK<=P, but are prohibited in targetSDK>=Q
Official reference:
Android Developer non-SDK interface restrictions:
https://developer.android.google.cn/guide/app-compatibility/restrictions-non-sdk-interfaces#test-for-non-sdk
9. Foreground service manager
Starting from Android 13 (API 33), a new item has been added to the Android notification bar 新特性
: the user can choose to stop the operation of " " through " "
in the notification bar .前台服务管理器
正在运行的前台服务
reference
Android Developer:Andoid13
https://developer.android.google.cn/about/versions/13
AOSP: Android13 Release Notes
https://source.android.google.cn/docs/setup/start/android-13-release
GoogleSource:Android13_r3
https://android.googlesource.com/platform/build/+/refs/tags/android-13.0.0_r4
= THE END =
The article was first published on the official account "CODING Technology Pavilion". If the article is helpful to you, please pay attention to my official account.