简体   繁体   中英

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

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. 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. In this case, pure notification pushes are drawn by the system.

Next thing is, that it depends on the Android version, what happens. Since (I think) Android 7, notification icons should be monochrome, so your ic_launcher is very likely not qualified to be a notification icon. You should design your own notification icon that is only white pixels with alpha.

Hope this helps, Cheers Gris

Use this

mBuilder.setSmallIcon(R.mipmap.ic_launcher_round);

not use this

mBuilder.setSmallIcon(R.mipmap.ic_launcher);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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