Android 14 适配之— BluetoothAdapter、JobScheduler、 Tiles

  1. BluetoothAdapter 改动:

在 BluetoothAdapter 中必须加入 BLUETOOTH_CONNECT 权限

Android 14(API 级别 34)或更高版本为目标的App,在调用函数 BluetoothAdapter getProfileConnectionState() 时,需要 BLUETOOTH_CONNECT

权限,

复制代码
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

AndroidManifest.xml 文件中声明 BLUETOOTH_CONNECT,并在调用 getProfileConnectionState 函数时,检查用户是否已授予权限检查用户是否已授予权限检查用户是否已授予权限

  1. JobScheduler 的改动

在Android14之前,obScheduler 会预计算您的应用在几秒内从 onStartJobonStopJob 返回,如果运行时间太长,系统则会停止其运行,以失败结束。在Android 14之后的版本,若在主线程上超出了授权的时间,App会被触发 ANR,并显示"onStartJob"没有响应或"onStopJob" 没有响应之类。替代方案,使用 WorkManager 异步处理,或者将复杂耗时操作移到后台线程执行。

在Android 14上,JobScheduler 调用 setRequiredNetworkTypesetRequiredNetwork 方法,需声明 ACCESS_NETWORK_STATE 权限;若未声明, 以Android 14 或更高版本为目标的App上,会产生 ​​​​​​​SecurityException 崩溃。

  1. TileService#startActivityAndCollapse(Intent)

Android 14之后,以上方法,已废弃,调用时会抛出异常。若App从功能块启动 activity,使用TileService#startActivityAndCollapse(PendingIntent) 方法

相关推荐
尘诞辰3 分钟前
【C语言】数据在内存中的储存
c语言·开发语言·数据结构·c++
JPX-NO3 分钟前
Rust + Rocket + Diesel构建的RESTful API示例(CRUD)
开发语言·rust·restful
running up4 分钟前
Spring IOC与DI核心注解速查表
java·后端·spring
YDS8295 分钟前
SpringCloud —— Sentinel详解
java·spring cloud·sentinel
无敌最俊朗@5 分钟前
STL-关联容器(面试复习4)
开发语言·c++
洛阳泰山6 分钟前
快速上手 MaxKB4J:开源企业级 Agentic 工作流系统在 Sealos 上的完整部署指南
java·人工智能·后端
封妖九禁苍天泣7 分钟前
Android WebView 使用本地字体-WebViewAssetLoader
android
bybitq8 分钟前
string,byte,rune,character?详解Golang编码-UTF-8
开发语言·后端·golang
guslegend8 分钟前
SpringSecurity授权原理与实战
java
添加shujuqudong1如果未回复9 分钟前
日志采集到分析:一条完整的流水线实战
android-studio