As we all know, we need to explicitly mention the type of foreground Service in the manifest for upgrading to android 14 from android 13, For most of the services i have included the line
android:foregroundServiceType="exampleType"
but there is one issue that, my project is a cordova based project with many flavors, and each flavor has its own manifest file, in that manifest file i have a line
<service android:name="org.apache.cordova.background.ForegroundService" />
which is basically representing the ForegroundService file from here, so i wanted to ask if a foregroundServiceType needs to be mentioned here as well and if yes then what should it be?
If your app targets Android 14, it must specify appropriate foreground service types.
How to Choose Service Type :
Foreground Service Types:
connectedDevice : Used for services interacting with connected devices (e.g., Bluetooth, USB).
dataSync : Suitable for services synchronizing data in the background.
health: For services related to health monitoring and fitness tracking.
location : Essential for services that continuously acquire or monitor the user's location.
media : The primary type for playing media (audio or video) in the background.
mediaProjection : Applies to services that utilize the media projection API for capturing or sharing the screen.
microphone: Only used for services requiring the microphone while running in the foreground.
phoneCall: Specific to services directly involved in phone calls or VoIP communication.
remoteMessaging: Used for services handling remote messaging like chat or notifications.
shortService: Applicable for short-lived foreground services completing tasks within a few seconds.
specialUse: Reserved for approved system partners for specific use cases.
systemExempted: Predefined by the system, not intended for general usage.
For Example if your are using
android:foregroundServiceType="mediaProjection" in service Manifest You need to handle service info in You respective Service class onStartCommand
Example code Handled for Both 14 and below devices
if (intent != null) { val serviceType = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) { 0 } else { ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION }
}
If you still need clarification you can visit this link which official developer documentation by google Please check this link