I've reviewed the Android 15 documentation, specifically the section on 'Restrictions on BOOT_COMPLETED broadcast receivers launching foreground services.'
It states that BOOT_COMPLETED receivers are restricted from launching the following types of foreground services: dataSync, camera, mediaPlayback, phoneCall, mediaProjection, microphone.
If a BOOT_COMPLETED receiver attempts to start any of these service types, the system throws a ForegroundServiceStartNotAllowedException.
However, my foreground service is of type shortService, and I'm encountering the following exception:
android.app.ForegroundServiceStartNotAllowedException: FGS type shortService not allowed to start from BOOT_COMPLETED!
Based on the documentation, shortService shouldn't trigger this exception. Could anyone suggest what I might be doing wrong or any workarounds for this issue?
In Android 14 (API level 34) and Android 15 (API level 35), the platform has introduced stricter restrictions on starting foreground services from certain contexts, including the BOOT_COMPLETED broadcast receiver. Despite your foreground service being of type shortService, you're encountering the ForegroundServiceStartNotAllowedException because Android 15 has a general restriction on starting any kind of foreground service directly from a BOOT_COMPLETED broadcast.
Due to Android 15's restrictions, starting any foreground service directly from the BOOT_COMPLETED receiver will likely trigger the exception. Instead, use WorkManager or JobScheduler to schedule the foreground service after a short delay, allowing the system to stabilize post-boot. This approach is safer and compliant with the new platform limitations.