网站关键词排名服务,做网络推广工作怎么样,铜陵市网站建设,山西省建设厅网站Google I/O 2023 发布的 Android beta2 #xff0c;Android 14 将在2023年第三季度发布。Google Play 已经开始强制要求targetSdkVersion 33适配#xff0c;所以 targetSdkVersion 34适配也是非常有必要的。 前台服务类型#xff08;Foreground service types are requiredAndroid 14 将在2023年第三季度发布。Google Play 已经开始强制要求targetSdkVersion 33适配所以 targetSdkVersion 34适配也是非常有必要的。 前台服务类型Foreground service types are required
前台服务类型foregroundServiceType是在 Android 10 引入的通过 android:foregroundServiceType 可以指定 service 的服务类型targetSdkVersion 34 的情况下必须为应用内的每个前台服务(foreground-services) 指定至少一种前台服务类型。此列表显示可供选择的前台服务类型
cameraconnectedDevicedataSynchealthlocationmediaPlaybackmediaProjectionmicrophonephoneCallremoteMessagingshortServicespecialUsesystemExempted
如果你 App 中的用例与这些类型中的任何一种都不相关那么建议还是将服务迁移成 WorkManager 或 jobs 。WorkManager or user-initiated data transfer jobs.
health、remoteMessaging、shortService、specialUse 和 systemExempted 类型是 Android 14 中的新类型。
manifest ...uses-permission android:nameandroid.permission.FOREGROUND_SERVICE /uses-permission android:nameandroid.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK /application ...serviceandroid:name.MyMediaPlaybackServiceandroid:foregroundServiceTypemediaPlaybackandroid:exportedfalse/service/application
/manifest 如果面向 Android 14 的应用未在清单中定义给定服务的类型则系统将在为该服务调用 startForeground() 时引发 MissingForegroundServiceTypeException。 声明使用前台服务类型的新权限
如果以 Android 14 为目标平台的应用使用前台服务则它们必须根据 Android 14 引入的前台服务类型声明特定权限。
uses-permission android:nameandroid.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK /serviceandroid:name.MyMediaPlaybackServiceandroid:foregroundServiceTypemediaPlaybackandroid:exportedfalse
/service
所有权限都定义为普通权限并默认授予。 用户无法撤销这些权限。
注意如果调用 startForeground() 时未声明适当的前台服务类型权限系统将抛出 SecurityException。 在运行时包括前台服务类型
启动前台服务的应用程序的最佳做法是使用 startForeground()。在其中传入前台服务类型的按位整数可以选择传递一个或多个类型值。
如果启动使用以下任何类型的前台服务则每次为该服务调用 startForeground() 时都应始终包含这些类型
FOREGROUND_SERVICE_TYPE_CAMERAFOREGROUND_SERVICE_TYPE_LOCATIONFOREGROUND_SERVICE_TYPE_MICROPHONE
Service.startForeground(0, notification, FOREGROUND_SERVICE_TYPE_LOCATION) 对implicit隐式和pending未决 intents意图的限制
对于面向 Android 14 的应用Android 通过以下方式限制应用向内部应用组件发送隐式意图
隐式 intent 仅传递给导出的组件应用必须使用明确的 intent 来交付给未导出的组件或者将组件标记为已导出exported 。如果应用创建一个 mutable pending intent 但 intent 未指定组件或包系统现在会抛出异常。
这些更改可防止恶意应用拦截只供给用内部组件使用的隐式 intent例如
activityandroid:name.AppActivityandroid:exportedfalseintent-filteraction android:namecom.example.action.APP_ACTION /category android:nameandroid.intent.category.DEFAULT //intent-filter
/activity
如果您的应用尝试使用隐式意图启动此活动则会抛出异常
// Throws an exception when targeting Android 14.
context.startActivity(Intent(com.example.action.APP_ACTION))
要启动未导出的 Activity您的应用应改用显式 Intent
// This makes the intent explicit.
val explicitIntent Intent(com.example.action.APP_ACTION)
explicitIntent.apply {package context.packageName
}
context.startActivity(explicitIntent) 运行时注册的广播接收器必须指定导出行为
以 Android 14 为目标并使用 context-registered receivers ContextCompat.registerReceiver的用和服务的需要指定一个标志以指示接收器是否应导出到设备上的所有其他应用分别为 RECEIVER_EXPORTED 或 RECEIVER_NOT_EXPORTED。通过利用 Android 13 中引入的这些接收器的功能此要求有助于保护应用免受安全漏洞的影响。
启用 DYNAMIC_RECEIVER_EXPLICIT_EXPORT_REQUIRED 兼容性框架更改。 在应用的每个广播接收器中明确指明其他应用是否可以向其发送广播如以下代码段所示
// This broadcast receiver should be able to receive broadcasts from other apps.
// This option causes the same behavior as setting the broadcast receivers
// exported attribute to true in your apps manifest.
context.registerReceiver(sharedBroadcastReceiver, intentFilter,RECEIVER_EXPORTED)// For app safety reasons, this private broadcast receiver should **NOT**
// be able to receive broadcasts from other apps.
context.registerReceiver(privateBroadcastReceiver, intentFilter,RECEIVER_NOT_EXPORTED)
仅接收系统广播的接收器例外
如果您的应用仅通过 Context#registerReceiver 方法例如 Context#registerReceiver()为系统广播注册接收器则在注册接收器时不应指定标志。 从后台启动Activity的限制
针对 Android 14 的应用系统限制了应用在后台启动 Activity
当应用使用 PendingIntent#send()发送 PendingIntent 以及类似行为时如果应用想要授予其自己的后台 service 启动权限以启动 pending intent则该应用现在必须选择加入一个 ActivityOptions 具体为带有 setPendingIntentBackgroundActivityStartMode(MODE_BACKGROUND_ACTIVITY_START_ALLOWED)当一个可见应用使用 bindService() 绑定另一个在后台运行的应用的服务时如果该可见应用想要将其自己的后台 activity 启动权限授予绑定服务则它现在必须选择加入 BIND_ALLOW_ACTIVITY_STARTS 标志。