简体   繁体   English

FCM 通知图标未更改

[英]FCM Notification Icon not changing

Why the hell does it keep displaying the default icon when I already changed the icon that should be displayed in the manifest.当我已经更改了应该在清单中显示的图标时,为什么它会继续显示默认图标。

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
    android:name=".FirebaseInitializer"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".TitleActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"></activity>

    <service android:name=".FirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

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

    <activity android:name=".AboutActivity"></activity>
</application>

My messaging service class extending FirebaseMessagingService我的消息服务类扩展 FirebaseMessagingService

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        createNotification(remoteMessage.getNotification().getBody());
    }

    private void createNotification(String message) {
        Intent intent = new Intent(this, TitleActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri notifSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Solitude")
                .setContentText(message)
                .setSound(notifSound)
                .setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, mNotificationBuilder.build());
    }
}

This is so frustrating.这太令人沮丧了。 Kindly please help me with my problem.请帮助我解决我的问题。

The manifest meta-data defines ic_launcher and your java code defines ic_launcher too.清单元数据定义了ic_launcher ,您的 Java 代码也定义了ic_launcher Where exactly should a different icon appear?不同的图标究竟应该出现在哪里? Or in other words: Exactly, which icon do you expect?或者换句话说:确切地说,您期望哪个图标?

Also, make sure you send a message with a data { ... } part, otherwise your service doesn't get called if the app is in background.另外,请确保您发送带有data { ... }部分的消息,否则如果应用程序在后台,则不会调用您的服务。 In this case, pure notification pushes are drawn by the system.在这种情况下,系统会绘制纯通知推送。

Next thing is, that it depends on the Android version, what happens.接下来是,这取决于 Android 版本,会发生什么。 Since (I think) Android 7, notification icons should be monochrome, so your ic_launcher is very likely not qualified to be a notification icon.由于(我认为)Android 7,通知图标应该是单色的,因此您的ic_launcher很可能不符合通知图标的条件。 You should design your own notification icon that is only white pixels with alpha.您应该设计自己的通知图标,该图标只有带有 alpha 的白色像素。

Hope this helps, Cheers Gris希望这会有所帮助,干杯 Gris

Use this用这个

mBuilder.setSmallIcon(R.mipmap.ic_launcher_round); mBuilder.setSmallIcon(R.mipmap.ic_launcher_round);

not use this不使用这个

mBuilder.setSmallIcon(R.mipmap.ic_launcher); mBuilder.setSmallIcon(R.mipmap.ic_launcher);

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

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