Go to page
and generate the notification icon.
You can also use the image generator
provided by Android Studio.
Move the downloaded icon image file to the android/app/src/res/drawable
folder.
If successful, it will appear as shown in the image below:
![image](https://private-user-images.githubusercontent.com/47127353/391226710-1ebe4750-def1-4387-a0ed-aeb8d4f483a4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjM4NDEsIm5iZiI6MTczOTU2MzU0MSwicGF0aCI6Ii80NzEyNzM1My8zOTEyMjY3MTAtMWViZTQ3NTAtZGVmMS00Mzg3LWEwZWQtYWViOGQ0ZjQ4M2E0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIwMDU0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTliMDZkMTYyZGIyZWI5MTI1ZGJiNGNiODViOTE4NDc2MmRjMWRkMmYzMWVhOTNhOGYxYWQzNmFmYTRlZGI5ZTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.CbwYgq1J8QblAhiDsPdR-9utQFDIr4EZyhrxDiPCQiI)
Next, you need to add meta-data in the AndroidManifest.xml
file so that the plugin can reference the icon resource.
<application>
<!-- Warning: Do not change service name. -->
<service
android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
android:foregroundServiceType="dataSync"
android:exported="false" />
<!-- this -->
<meta-data
android:name="com.your_package.service.HEART_ICON"
android:resource="@drawable/ic_heart" />
</application>
The name of the meta-data can be customized, but it is recommended to set it to a unique name combined with your package name.
Finally, you can create a NotificationIcon object to change the notification icon when starting or updating the service.
void start() {
FlutterForegroundTask.startService(
notificationTitle: 'notificationTitle',
notificationText: 'notificationText',
notificationIcon: const NotificationIcon(
metaDataName: 'com.your_package.service.HEART_ICON',
backgroundColor: Colors.orange,
),
);
}
void update() {
FlutterForegroundTask.updateService(
notificationIcon: const NotificationIcon(
metaDataName: 'com.your_package.service.HEART_ICON',
backgroundColor: Colors.purple,
),
);
}