简体   繁体   English

Android & iOS 使用 flutter_launcher_icons 0.9.2 时的通知图标(灰色)

[英]Android & iOS notification icons (grey) while using flutter_launcher_icons 0.9.2

I believe the question has been asked in various places like GitHub, Stackoverflow, Reddit & other forums.我相信这个问题已经在 GitHub、Stackoverflow、Reddit 和其他论坛等不同地方被问到。

Using flutter and firebase notifications some devices are generating 'grey area' icons when receiving a notification.使用 flutter 和 firebase 通知时,某些设备在收到通知时会生成“灰色区域”图标。

For example: I've used the plugin flutter_launcher_icons 0.9.2 Which generates icons for both iOS & Android, also updates AndroidManifest.xml file for android. code below:例如:我使用了 flutter_launcher_icons 0.9.2 插件,它为 iOS 和 Android 生成图标,还为 android 更新 AndroidManifest.xml 文件。代码如下:

    package="xxxxxxDeletedxxxxx">
   <application
        android:label="xxxxxxDeletedxxxxx"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name="xxxxxx"
            android:exported="true"
            android:launchMode="singleTask"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
            <meta-data
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@drawable/ic_launcher" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="https"
                    android:host="xxxx" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
   </manifest>

The AndroidManifest.xml files indicates, that path for Icon has been set and the icons are generated. AndroidManifest.xml 文件表明,已设置 Icon 的路径并生成图标。

To troubleshoot:排除故障:

I've added same icon in both drawable and mipmap (found on github that this might help).我在 drawable 和 mipmap 中添加了相同的图标(在 github 上找到,这可能有帮助)。 [https://i.stack.imgur.com/OGGtj.png] [https://i.stack.imgur.com/OGGtj.png]

The end result ->最终结果->

Samsung s10 receives notification with the expected icon.三星 s10 收到带有预期图标的通知。 Pixel 6 phone(physical) or a random emulator with Android 27lvl API shows grey area icon . Pixel 6 手机(实体)或带有 Android 27lvl API 的随机模拟器显示灰色区域图标

There are multiple answers/solutions but none of them are pointing to what is actually causing the main problem.有多个答案/解决方案,但没有一个指向实际导致主要问题的原因。

I understand this is a repeated question, but there are no proper solutions/documentation to this case.我知道这是一个反复出现的问题,但没有针对此案例的适当解决方案/文档。 I'm sure other people will benefit from it.我相信其他人会从中受益。

Regards问候

Some phones need monochrome notification icons with transparent background.有些手机需要具有透明背景的单色通知图标。 So if you don't have transparent background, all colours will be converted to one and you will only see monochrome circle/square.因此,如果您没有透明背景,所有颜色都将转换为一种颜色,您将只能看到单色圆圈/正方形。 Also meta-data inside activity didn't worked for me, so you can try to move it outside, something like this:活动中的元数据也对我不起作用,因此您可以尝试将其移到外面,如下所示:

<application>
<activity>
   ...
</activity>

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_notification" /></application>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM