startForeground static method
- @Deprecated("This method is deprecated. You should use startAndroidForegroundService instead.")
- required NotificationContent content,
- List<
NotificationActionButton> ? actionButtons, - int startType = AndroidForegroundServiceConstants.startSticky,
- int? foregroundServiceType,
Starts the foreground service with the given notification
, whichs content must not be null
.
The notification can be updated by simply calling this method multiple times.
Information on selecting a appropriate startType
for your app's usecase should be taken from the
official Android documentation, check Service.onStartCommand
.
The notifcation.content.locked
property will be forced to true
to achive an ongoing
notificaiton suitable for a foreground service. Also, notification.schedule
will be cleared, since the notifcation needs to be shown right away when the foreground service is started.
If foregroundServiceType
is set, Service.startForeground(int id, Notification notification, int foregroundServiceType)
will be invoked , else Service.startForeground(int id, Notification notification)
is used.
On devices older than Build.VERSION_CODES.Q
, foregroundServiceType
will be ignored.
Multiple type flags can be ORed together (using the |
operator).
Note that foregroundServiceType
must be a subset of the android:foregroundServiceType
defined in your AndroidManifest.xml
!
On any platform other than Android, this is a no-op and does nothing, so it is safe to call it without a platform check.
Implementation
@Deprecated(
"This method is deprecated. You should use startAndroidForegroundService instead.")
static Future<void> startForeground(
{required NotificationContent content,
List<NotificationActionButton>? actionButtons,
int startType = AndroidForegroundServiceConstants.startSticky,
int? foregroundServiceType}) async {
//no-op on web
}