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) 方法

相关推荐
一方热衷.1 小时前
YOLO26-Seg ONNXruntime C++/python推理
开发语言·c++·python
靓仔建2 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
HalvmånEver3 小时前
7.高并发内存池大页内存申请释放以及使用定长内存池脱离new
java·spring boot·spring
凤山老林3 小时前
SpringBoot 使用 H2 文本数据库构建轻量级应用
java·数据库·spring boot·后端
赶路人儿4 小时前
UTC时间和时间戳介绍
java·开发语言
dreamread4 小时前
【SpringBoot整合系列】SpringBoot3.x整合Swagger
java·spring boot·后端
6+h4 小时前
【java】基本数据类型与包装类:拆箱装箱机制
java·开发语言·python
一直都在5724 小时前
Spring面经
java·后端·spring
xiaoye37084 小时前
如何在Spring中使用注解配置Bean的生命周期回调方法?
java·spring
闻哥4 小时前
深入Redis的RDB和AOF两种持久化方式以及AOF重写机制的分析
java·数据库·spring boot·redis·spring·缓存·面试