The functionality of this package was integrated directly into awesome_notifications see here.
There are already serveral packages on pub that allow you to create an Android foreground service. Since an Android foreground service always needs an Android notification, most of the plugins come with an own notification system.
On the other hand, the most used notification system for flutter is awesome_notifications, and chances are that your app already uses it.
The problem is now that you don't want to have two API's for notifications: one for the foreground service and one for awesome_notifications
.
So this package provides a foreground service that uses awesome_notifications PushNotification
class, and also uses it's java side algorithms to convert that dart object into an Android notification.
That is possible because in flutter you can import java classes from other packages.
While the foreground service permission is automatically added by this plugin, you have to add the <service>
tag manually to your AndroidManifest.xml
. Theoretically, the service could have been declarded by this plugin, too, but you might wan't to use other parameters, so we opted to let you add it. Inside your <application>
tag add
<service android:name="eu.epnw.afswan.ForegroundService"
android:enabled="true"
android:exported="false"
android:stopWithTask="true"
android:foregroundServiceType=As you like
></service>
While the android:name
must exactly match this value, you can configure the other parameters as you like, although it is recommended to copy the values for android:enabled
, android:exported
and android:stopWithTask
. Suitable values for foregroundServiceType
can be found here.
If the icon of the notification is not set or not valid, the notification will appear, but will look very strange. Make sure to always specify an valid icon. If you need help with this, take a look at awesome_notifications examples.
On any platform other then Android, all methods in this plugin are no-ops (they do nothing when called), so you don't need to do a platform check before calling them.
Yes, android_foreground_service_with_awesome_notifications
is a very long plugin name, but on the other hand very precise and tells you what this plugin does, just by reading the title. In some places we use AFSWAN
as abbreviation.