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

相关推荐
周杰伦fans13 小时前
C#中OrderByDescending 是LINQ扩展方法之一
开发语言·c#·linq
李绍熹13 小时前
Lua 语言基础教程
开发语言·junit·lua
周杰伦fans13 小时前
C# 中 SQL Server 数据库调优指南(小白友好版)
开发语言·数据库·c#
1***y17813 小时前
PHP在微服务中的微服务开发
开发语言·微服务·php
b***666114 小时前
Spring Boot 整合 Apollo 配置中心实战
java·spring boot·后端
CoderYanger14 小时前
递归、搜索与回溯-综合练习:27.黄金矿工
java·算法·leetcode·深度优先·1024程序员节
大吱佬14 小时前
GO 八股整理(自用)
开发语言·后端·golang
froginwe1114 小时前
Go 语言结构体
开发语言
vx_vxbs6614 小时前
【SSM高校普法系统】(免费领源码+演示录像)|可做计算机毕设Java、Python、PHP、小程序APP、C#、爬虫大数据、单片机、文案
android·java·python·mysql·小程序·php·idea
张较瘦_14 小时前
Springboot3 | ResponseEntity 完全使用教程
java·springboot·开发