unity firebase 通知自定义图片

P. *_*era 5 icons unity-game-engine firebase firebase-cloud-messaging

我决定在我的统一项目中实施 Firebase 通知。问题是对于通知,我想使用自定义图像,但该图像也用作应用程序图像 (app_icon)。我试图修改我放入 MessagingUnityPlayerActivity 活动自定义通知图像(notificon)以显示通知图标的清单。

<?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>
Run Code Online (Sandbox Code Playgroud)

我试图修改它并删除一些标签,但随后构建无法编译。我还应该提到我的项目中有多个清单,并尝试将它们合并在一起但没有成功。但这不应该是问题,因为这是 android:icon 属性的唯一清单。

谢谢

小智 5

  1. 在文件夹“Assets\Plugins\Android\res\drawable”下制作一个图像(游戏图标的白色透明版本,png)。
  2. 就我而言,图像的名称是“small_icon.png”,然后在“Assets\Plugins\Android\AndroidManifest.xml”中,在打开标签后添加它:

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

你的 AndroidManifest.xml 应该是这样的

<?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>
....
Run Code Online (Sandbox Code Playgroud)


MGG*_*GGD 0

无需更改清单。对我有用:

因此,您应该能够将图标添加到 Assets/Plugins/Android/res/drawable/ 并引用它的名称

然后,在通知 json 中指定您的图标。例如:

"notification": {
        "title": "Title",
        "body" : "First Notification",
        "text" : "Text",
        "icon" : "MyIcon"
    }
Run Code Online (Sandbox Code Playgroud)

注意:我使用了这些图标之一。