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

相关推荐
呱牛do it11 小时前
企业级门户网站设计与实现:基于SpringBoot + Vue3的全栈解决方案(Day 3)
java·vue
神の愛12 小时前
左连接查询数据 left join
java·服务器·前端
t***54412 小时前
如何配置Orwell Dev-C++使用Clang
开发语言·c++
CoderCodingNo12 小时前
【信奥业余科普】C++ 的奇妙之旅 | 13:为什么 0.1+0.2≠0.3?——解密“爆int”溢出与浮点数精度的底层原理
开发语言·c++
南境十里·墨染春水12 小时前
linux学习进展 线程同步——互斥锁
java·linux·学习
雨奔12 小时前
Kubernetes 联邦 Deployment 指南:跨集群统一管理 Pod
java·容器·kubernetes
杨凯凡12 小时前
【021】反射与注解:Spring 里背后的影子
java·后端·spring
lulu121654407812 小时前
Claude Code项目大了响应慢怎么办?Subagents、Agent Teams、Git Worktree、工作流编排四种方案深度解析
java·人工智能·python·ai编程
riNt PTIP12 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring
alexhilton13 小时前
Compose中的CameraX二维码扫描器
android·kotlin·android jetpack