Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 418
P. Vitvera Avatar asked Oct 17 '22 17:10

P. Vitvera


1 Answers

  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>
....
like image 130
Anh Ngọc Avatar answered Oct 21 '22 07:10

Anh Ngọc