OnNotificationOpened called every time App is launched on Android, without tapping notifications, Xamarin Forms
See original GitHub issue๐ Bug Report
Configuration
In release build, whenever I launch my App by tapping its icon, the CrossFirebasePushNotification.Current.OnNotificationOpened
is fired even though no notification has been tapped on or received. This does not happen while debugging the app. However, If I stop debugging, and just tap the debug build version of the App and it opens, still the same event is fired. Only when connected to Visual Studio and started in debug mode from there is the event not fired.
Plugin.FirebasePushNotification version 3.3.13-beta (tried version 3.3.10 but still the same) Xamarin Forms v4.6.0.616-pre4
MainApplication.cs
[Application]
public class MainApplication : Application
{
protected MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
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 = "DefaultChannel";
//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
}
FirebasePushNotificationManager.NotificationActivityType = typeof(MainActivity);
//If debug you should reset the token each time.
#if DEBUG
FirebasePushNotificationManager.Initialize(this,true,true,false);
#else
PushNotificationManager.Initialize(this,false,true,false);
#endif
CrossFirebasePushNotification.Current.OnNotificationOpened += async (s,p) =>
{
Toast.MakeText(Application.Context, "Why on earth is this toast appearing when i just launched the app normally", ToastLength.Short).Show();
};
}
}
MainActivity.cs
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
FirebasePushNotificationManager.ProcessIntent(this,intent);
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.Window.RequestFeature(WindowFeatures.ActionBar);
base.SetTheme(Resource.Style.AppTheme);
FormsAppCompatActivity.ToolbarResource = Resource.Layout.Toolbar;
FormsAppCompatActivity.TabLayoutResource = Resource.Layout.Tabbar;
base.OnCreate(savedInstanceState);
// Inicializando FFImageLoading
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
var config = new Configuration
{
ExecuteCallbacksOnUIThread = false,
HttpClient = new HttpClient(new AndroidClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
}),
};
FFImageLoading.ImageService.Instance.Initialize(config);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
// Inicializando Xamarin.Essentials
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
LoadApplication(new App());
FirebasePushNotificationManager.ProcessIntent(this,Intent);
}
What am I missing?
Platform:
- ๐ฑ iOS
- [X ] ๐ค Android
- ๐ WPF
- ๐ UWP
- ๐ MacOS
- ๐บ tvOS
- ๐ Xamarin.Forms
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
OnNotificationOpened not fired on Android when ...
OnNotificationOpened not fired on Android when notification is tapped while app is closed. (Xamarin.Forms) #430.
Read more >c# - Xamarin.Forms Firebasepushnotification plugin ...
I'm trying to handle a notifications opening on android that I've sent through Google's FCM on the SharedProject level by using "Plugin.
Read more >Implement push notification tapping on android platform
I have implemented push notification on my Xamarin forms application using FCM. Here I am using notifications for the messages. So when I...
Read more >Push notifications made easy in Xamarin
On iOS by default you need to tap the notification to receive the data. OnNotificationOpened โ When a push notification is opened you...
Read more >Getting Started with Push Notifications
When a push is received in the foreground on iOS, how the notification is displayed to the user is controlled by foreground presentation...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Itโs better to move to Xamarin OneSignal
Guys, I might have found a solution for this problem. It seems as Android recycles the Intent which launched an Activity (and with the Intent it recycles the Extras in it). I tested several scenarios and it looks like the following code can be used in OnCreate an OnNewIntent (instead of just calling FirebasePushNotificationManager.ProcessIntent):
Is this something, they should integrate into this plugin? Or anyone still doing maintenance here?