我正在嘗試更改從 firebase 收到的推送通知的內容。這是Android專案中的應用程式類:
public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
//Set the default notification channel for your app when running Android Oreo
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
//Change for your default notification channel id here
FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";
//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
FirebasePushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.Max;
}
//If debug you should reset the token each time.
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this, false);
#endif
FirebasePushNotificationManager.IconResource = Resource.Drawable.logogiusto;
FirebasePushNotificationManager.Color = Android.Graphics.Color.Red;
//Handle notification when app is closed here
CrossFirebasePushNotification.Current.OnNotificationReceived = (s, p) =>
{
//var hardware_token=Xamarin.Essentials.SecureStorage.GetAsync("hardware_token");
//Interface inter = new Interface();
//float share=inter.GetShareOnHardwareToken(hardware_token);
FirebasePushNotificationManager.NotificationContentTitleKey = "foobar";
System.Diagnostics.Debug.WriteLine(FirebasePushNotificationManager.NotificationContentTitleKey);
};
}
基本上,我需要使用一些只能通過用戶應用程式獲取的資料來更改通知內容(直到會話過期)*。我考慮過使用令牌而不是主題來處理它,但由于該應用程式需要同時向用戶發送通知,所以它在我這邊可能會變得笨重。
我也嘗試過使用
FirebasePushNotificationManager.NotificationContentTitleKey = "foobar";
正如您從上面的代碼中看到的那樣,但它根本什么都不做,內容仍然是我在 firebase 上選擇的內容。
一個有趣的方面是,每當我收到來自 firebase 的推送通知時,我都會在除錯視窗中看到它:
[FirebaseMessaging] Unable to log event: analytics library is missing
[FirebaseMessaging] Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
雖然我不能完全理解這是指什么。
*如果我從 Firebase收到的是來自 FIREBASE 的新通知,則它需要成為來自 ABC 的新通知
uj5u.com熱心網友回復:
正確設定元名稱,以便可以識別默認通知通道,如下所示:
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/notification_channel_id" />
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/406452.html
標籤:
