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

相关推荐
q***649721 分钟前
Spring BOOT 启动参数
java·spring boot·后端
百***784524 分钟前
Java实战:Spring Boot application.yml配置文件详解
java·网络·spring boot
你不是我我33 分钟前
【Java 开发日记】SQL 语句左连接右连接内连接如何使用,区别是什么?
java·javascript·数据库
ghie909036 分钟前
C#语言中使用“using“关键字的介绍
开发语言·c#
七夜zippoe1 小时前
Java性能调优工具篇:JMH基准测试与Profiler(JProfiler/Async-Profiler)使用指南
java·开发语言·jprofiler·jmh·async-profiler
從南走到北1 小时前
JAVA国际版二手车交易二手车市场系统源码支持Android+IOS+H5+APP
android·java·ios
江上清风山间明月1 小时前
Android 系统中进程和线程的区别
android·python·线程·进程
Kuo-Teng1 小时前
LeetCode 19: Remove Nth Node From End of List
java·数据结构·算法·leetcode·链表·职场和发展·list
北i1 小时前
TiDB 关联子查询去关联优化实战案例与原理深度解析
java·数据库·sql·tidb
Kuo-Teng1 小时前
LeetCode 21: Merge Two Sorted Lists
java·算法·leetcode·链表·职场和发展