![](/img/trans.png)
[英]Why are HTTP image URLs not working with Firebase iOS push notifications?
[英]Unity firebase notifications custom image
我決定在我的統一項目中實施 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>
我試圖修改它並刪除一些標簽,但隨后構建無法編譯。 我還應該提到我的項目中有多個清單並嘗試將它們合並在一起但沒有成功。 但這不應該是問題,因為這是唯一具有 android:icon 屬性的清單。
謝謝
使用 AAB 將res
文件夾放在Assets/Plugins/Android
中已經過時,並且會阻止您構建。
由於我懶得安裝 Android Studio 來構建自定義 AAR,我通過將 ZIP-Archive 放入Assets/Plugins/Android
文件夾中解決了這個問題,其中包含res
文件夾(res 文件夾是用這個創建的,如另一個答案中所述)以及res
文件夾旁邊的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="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>
然后在資源管理器中將ZIP文件擴展名改成AAR。 然后您可以從發件人端指定圖標名稱。 有關 AAR 剖析的更多詳細信息,請參見 此處。
<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>
....
然后在資源管理器中將ZIP文件擴展名改成AAR。 然后您可以從發件人端指定圖標名稱。 有關 AAR 剖析的更多詳細信息,請參見 此處。
如果你只是將擴展名更改為 aar,它將無法編譯。
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':unityLibrary:compileReleaseJavaWithJavac'.
> Could not resolve all files for configuration ':unityLibrary:releaseCompileClasspath'.
> Failed to transform firebase_notification_icon-.aar (:firebase_notification_icon:) to match attributes {artifactType=android-classes-jar, org.gradle.status=integration, org.gradle.usage=java-api}.
> Execution failed for AarToClassTransform: C:\...\.gradle\caches\transforms-2\files-2.1\ea6ac2b3d0993f0958d52cbbdfbd76ea\jetified-firebase_notification_icon.aar.
> entry
AAR 文件必須在 Android Studio 中創建。 由於它必須包含一些必需的文件,例如AndroidManifest.xml、classes.jar等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.