Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging: How to set the notification icon on android?

I am having trouble setting the notification icon on android studio.

I set up the drawable folder like so:

enter image description here

And I've also set the default icon in my AndroidManifest.xml file:

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

And here I'm setting the icon field to notification_icon: https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json (p.s. I'm aware that's GCM, but it works. I'm receiving the notification with everything besides the icon)

What am I missing? All I see is a white square inside a grey circle.

This is my backend code: Pushex.push(%{title: user.name, body: "message goes here", badge: 1, sound: "default", icon: "notification_icon"}, to: user.fcm_token, using: :gcm) (https://github.com/tuvistavie/pushex)

like image 855
bigpotato Avatar asked Jun 30 '17 11:06

bigpotato


1 Answers

With SDK 9.8.0 however, you can override the default! In your AndroidManifest.xml you can set the following fields to customise the icon and color:

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

and

<manifest>
<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name">

    <!-- Add your meta-data here-->

    <activity 
        android:name=".MainActivity" 
        android:label="@string/app_name">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

</application>

like image 169
Faxriddin Abdullayev Avatar answered Sep 25 '22 18:09

Faxriddin Abdullayev