'Unity firebase notifications custom image

I have decided to implement Firebase notifications into my unity project. The issue is that for notifications I want to use custom image, but that image is also used as app image (app_icon). I tried to modify manifest where I put into MessagingUnityPlayerActivity activity custom notification image (notificon) for displaying notification icon.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="${applicationId}"
          android:versionCode="1"
          android:versionName="1.0">
  <application android:label="@string/app_name"
               android:icon="@drawable/app_icon">
    <!-- The MessagingUnityPlayerActivity is a class that extends
         UnityPlayerActivity to work around a known issue when receiving
         notification data payloads in the background. -->
    <activity android:name="com.google.firebase.MessagingUnityPlayerActivity"
              android:label="@string/app_name"
              android:icon="@drawable/notificon"
              android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <service android:name="com.google.firebase.messaging.MessageForwardingService"
             android:exported="false"/>
  </application>

</manifest>

I tried to modify it and delete some tags, but then the build wond compile. I should also mention that I have multiple manifests in my project and tried them to merge together but unsuccessfully. But this shouldnt be the problem since this is the only manifest with android:icon propery.

Thank you



Solution 1:[1]

  1. Make an image (a white on transparent version of game icon, png) under folder "Assets\Plugins\Android\res\drawable.
  2. In my case, the name of my image is "small_icon.png" then in "Assets\Plugins\Android\AndroidManifest.xml", add it after opening tag:

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

Your AndroidManifest.xml should be like

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" package="${applicationId}" 
android:versionCode="1" android:versionName="1.0">
  <application android:label="@string/app_name" android:icon="@drawable/app_icon">

<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/small_icon" />
<activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
....

Solution 2:[2]

No need to change the manifest. This worked for me:

So you should be able to add your icon(s) to Assets/Plugins/Android/res/drawable/ and reference it name

Then, in the notification json, specify your icon. For example:

"notification": {
        "title": "Title",
        "body" : "First Notification",
        "text" : "Text",
        "icon" : "MyIcon"
    }

Note: I used one of these icons.

Solution 3:[3]

Putting a res folder inside Assets/Plugins/Android using AAB is obsolete and will prevent you from building.

Since I was too lazy to install Android Studio to build a custom AAR I solved it by placing a ZIP-Archive into the Assets/Plugins/Android folder, with the res folder inside (res folder created with this as mentioned in an other answer) and the following snippet inside a AndroidManifest.xml next to the res folder:

<?xml version="1.0" encoding="utf-8"?>
<manifest 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
package="com.google.firebase.messaging" 
android:versionCode="1" 
android:versionName="1.0">
<application>
<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/YOURICONIMAGENAMEWITHOUTEXTENSION" />
        </application>
</manifest>

Then change the ZIP file extension to AAR in the explorer. You can then specify the icons name from the senders side. More details of the AAR anatomy here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anh Ng?c
Solution 2 MGGD
Solution 3 Codehai