Skip to content

Latest commit

 

History

History
54 lines (43 loc) · 1.92 KB

customize_notification_icon.md

File metadata and controls

54 lines (43 loc) · 1.92 KB

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

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,
    ),
  );
}