7

I'm new in flutter so please don't kill me if my question is easy.

notification icon doesn't show like this

enter image description here

I put in this path

\android\app\src\main\res\drawable

here is my code for icon:

 final settingsAndroid = AndroidInitializationSettings('app_icon');
 final settingsIOS = IOSInitializationSettings(onDidReceiveLocalNotification: (id, title, body, payload) => onSelectNotification(payload));
 final settingsIOSgeneral = IOSInitializationSettings(onDidReceiveLocalNotification: (id, title, body, payload) => onSelectNotificationgeneral(payload));
 notifications.initialize(InitializationSettings(settingsAndroid, settingsIOS), onSelectNotification: onSelectNotification);

Can Any one help me please how can I preview my icon in notification ?

Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56
Eman Fateen
  • 821
  • 2
  • 9
  • 14
  • Looks like a proguard issue, see this https://stackoverflow.com/a/61303224/8912043 – Taz Feb 07 '22 at 07:28

6 Answers6

13

I did the following and it worked for me:

  1. Create a transparent and white notification icon (you can use the following tool: AndroidAssetStudio )

Download the zip folder, unzip and you'll see it contains a res folder with different drawable folders. Copy and paste the contents of the res folder in "android\app\src\main\res" path

Folder Structure

  1. Then open the AndroidManifest.xml file and add the following lines to it:

ic_stat_calendar_today is the name of my notification icon. And each of the drawable folders that have been pasted contain a different size of icon with the same name.

Android Manifest

  1. If you want to change the color of the icon then check the above image. Add the metadata tag after the notification icon tag

  2. Go to "android\app\src\main\res\values" and add a colors.xml file

colors.xml

<color name="colorAccent">#00FF00</color>

I have shared this answer in the following Github chain as well- Solution.

user2549980
  • 593
  • 7
  • 20
4

This could be because the icon image is not transparent -- Try the notification icon generated from this tool. Also check this question Android Push Notifications: Icon not displaying in notification, white square shown instead

Sandeep Chayapathi
  • 1,490
  • 2
  • 13
  • 31
1

generate a transparent icon and then set the color in AndroidNotificationDetails parameter

kk.
  • 3,747
  • 12
  • 36
  • 67
Zahra Jamshidi
  • 681
  • 6
  • 9
0

You must do three things;

1.follow @user2549980's answer and do samethins step by step but in colors.xml file, you must write encoding="utf-8" with uppercase format, like;

(your notification icon must be copied mipmap folders with same sizes, and you must add that icon name to your AndroidManifest.xml, and it must be transparent icon.)

2.Step; in your local notification init function,

 _notificationPlugin=FlutterLocalNotificationsPlugin();

await _notificationPlugin.initialize(
    const InitializationSettings(
        android: AndroidInitializationSettings('@mipmap/notification_icon'),
        iOS: IOSInitializationSettings()
    ),
  onSelectNotification: (payload) async{

  
  },
);

you must change this line @mipmap/icon_name with your icon name.

and I am writing this comment because, this step can be missed easily so, don't forget this step.

leylekseven
  • 687
  • 7
  • 15
0

(1) You don't have to put them in drawable, you can put them in mipmap (android/src/main/res/mip-map-**dpi folders) if you want. (2) If you need to test the result, hotreload won't take effect, you have to rebuild to test the result.

AlanGuoDev
  • 41
  • 1
0

Icon should be transparent or BG is white use this website to remove if you want https://www.remove.bg/upload

then open you project in Android studio, you can easily create them with the built-in tool in Android Studio. Right-click on Res folder -> New -> Image Asset -> Notification Icon (select from dropdown) there you can select any svg or image from the gallery.

then change final

AndroidInitializationSettings initializationSettingsAndroid =
        AndroidInitializationSettings('ic_notification');

ic_notification name is my image it is there in drawable folder enter image description here

it will work.

saigopi.me
  • 14,011
  • 2
  • 83
  • 54