Note: If an app that targets API level 28 or higher attempts to create a foreground service without requesting the FOREGROUND_SERVICE permission, the system throws a SecurityException. Similarly, if an app targets API level 34 or higher and doesn't request the appropriate specific permission, the system throws SecurityException.
and
Inside the service, usually in onStartCommand(), you can request that your service run in the foreground. To do so, call ServiceCompat.startForeground() (available in androidx-core 1.12 and higher). This method takes the following parameters:
The service
A positive integer that uniquely identifies the notification in the status bar
These types might be a subset of the types declared in the manifest, depending on the specific use case. Then, if you need to add more service types, you can call startForeground() again.
These changes modify AndroidNotificationOptions to allow the developer to specify the bitmap sum of permissions with which the service will be launched (via ServiceCompat.startForeground as mentioned above). This also adds a class of constants AndroidForegroundServiceType.dart for the user to easily sum up the permissions they need:
This is already merged. You can use foregroundServiceType and use bitwise operator : foregroundServiceType: AndroidForegroundServiceType.SPECIAL_USE | AndroidForegroundServiceType.CAMERA
My use-case is as follows
From the relevant Android docs:
and
These changes modify
AndroidNotificationOptions
to allow the developer to specify the bitmap sum of permissions with which the service will be launched (viaServiceCompat.startForeground
as mentioned above). This also adds a class of constants AndroidForegroundServiceType.dart for the user to easily sum up the permissions they need:e.g.