簡體   English   中英

FCM 通知圖標未更改

[英]FCM Notification Icon not changing

當我已經更改了應該在清單中顯示的圖標時,為什么它會繼續顯示默認圖標。

<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>

我的消息服務類擴展 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());
    }
}

這太令人沮喪了。 請幫助我解決我的問題。

清單元數據定義了ic_launcher ,您的 Java 代碼也定義了ic_launcher 不同的圖標究竟應該出現在哪里? 或者換句話說:確切地說,您期望哪個圖標?

另外,請確保您發送帶有data { ... }部分的消息,否則如果應用程序在后台,則不會調用您的服務。 在這種情況下,系統會繪制純通知推送。

接下來是,這取決於 Android 版本,會發生什么。 由於(我認為)Android 7,通知圖標應該是單色的,因此您的ic_launcher很可能不符合通知圖標的條件。 您應該設計自己的通知圖標,該圖標只有帶有 alpha 的白色像素。

希望這會有所幫助,干杯 Gris

用這個

mBuilder.setSmallIcon(R.mipmap.ic_launcher_round);

不使用這個

mBuilder.setSmallIcon(R.mipmap.ic_launcher);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM