Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ic_launcher icon not working for android push notifications #537

Open
desmeit opened this issue Jan 17, 2024 · 2 comments
Open

ic_launcher icon not working for android push notifications #537

desmeit opened this issue Jan 17, 2024 · 2 comments

Comments

@desmeit
Copy link

desmeit commented Jan 17, 2024

I added flutter_launcher_icons: ^0.13.1 to my flutter project:

flutter_launcher_icons:
  android: "ic_launcher"
  ios: true
  image_path: "assets/icon.png"
  remove_alpha_ios: true
  adaptive_icon_background: "assets/ic_background.png"
  adaptive_icon_foreground: "assets/ic_logo.png"

all icons are working except the push notifications. the icon in the push notifications looking like this:

Screenshot_20240117-123003

Bildschirmfoto 2024-01-17 um 12 24 35

i thinks its because of the missing ic_launcher icon in the folder because in my manifest I have:

android:icon="@mipmap/ic_launcher"

How is the right way to implement the push notifications icon with this plugin?

[✓] Flutter (Channel stable, 3.16.5, on macOS 14.1.2 23B92 darwin-arm64, locale de-DE)
    • Flutter version 3.16.5 on channel stable at /Users/xxx/development/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (vor 4 Wochen), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/xxx/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/xxx/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/xxx/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.85.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (4 available)
    • Pixel 6a (mobile)       • 35171JEGR02908            • android-arm64  • Android 13 (API 33)
    •iPhone (mobile) • 00008130-000A49440230001C • ios            • iOS 17.2.1 21C66
    • macOS (desktop)         • macos                     • darwin-arm64   • macOS 14.1.2 23B92 darwin-arm64
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 120.0.6099.216
    ! Error: Browsing on the local area network for xxx iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!
@emri99
Copy link

emri99 commented Feb 21, 2024

Hello,

I was facing the same issue, and now that it's resolved I don't think this plugin is responsible.

Here's the workaround I've found.

My push notification provider is Batch, and use FirebaseCloudMessaging internally, so I first add a section in the application part of AndroidManifest.xml :

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
     See README(https://goo.gl/l4GJaQ) for more. -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_launcher_foreground" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
     notification message. See README(https://goo.gl/6BKBk7) for more. -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/ic_launcher_background" />

From : https://firebase.google.com/docs/cloud-messaging/android/client#manifest
(I only add the optional section about icon)

Unfortunately, the icon was visible but icon background color was always black.
I resolve this issue by following Batch documentation, the naming of properties above are slightly different.

Notice: the icon for notification is used as a mask. That implies it must have a transparent background and all colored part will have same color when shown in notification context.

Hope my xp can lead you to a fix 😃 🤞

@desmeit
Copy link
Author

desmeit commented Mar 25, 2024

@emri99 thanks.
I found a fix as well:

  • name your icon "app_icon.png" and place it in the drawable folder
  • edit your keep.xml in the raw folder: tools:keep="@drawable/*,@raw/sound" (if your soundfile name is sound.mp3)
  • add the name of the file in the settings: AndroidInitializationSettings('app_icon');

keep in mind:
notification icon should be white on transparent color. you can create it in Android Studio > right click on resources > New Image Asset > Notification Icon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants