Plugin.LocalNotification NotificationTapped event does not work with Prism.DryIoc.Forms on Android
See original GitHub issueDescribe the bug I tried using Plugin.LocalNotification in my Prism.Forms.DryIoc project, Notification trigger, channel, receive event, everything works except NotificationTapped event. When a notification is tapped, the app just relaunched. Is there anything I’m doing wrongly, or is there any specific way need to be handled before using local notification on Prism project?
To Reproduce Steps to reproduce the behavior: You can refer to my repository: https://github.com/maxchu92/PrismLocalNotificationBug
- Install NuGet Package of Plugin.LocalNotification [https://github.com/thudugala/Plugin.LocalNotification]
- Implement Android extra step.
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
.....
// Must create a Notification Channel when API >= 26
// you can created multiple Notification Channels with different names.
NotificationCenter.CreateNotificationChannel();
.....
LoadApplication(new App());
.....
NotificationCenter.NotifyNotificationTapped(Intent);
}
protected override void OnNewIntent(Intent intent)
{
NotificationCenter.NotifyNotificationTapped(intent);
base.OnNewIntent(intent);
}
}
- Implement Tap event in the App.xaml.cs or AnyPage.xaml.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
// Local Notification tap event listener
NotificationCenter.Current.NotificationTapped += OnLocalNotificationTapped;
MainPage = new MainPage();
}
private void OnLocalNotificationTapped(NotificationTappedEventArgs e)
{
Device.BeginInvokeOnMainThread(()=>{
DisplayAlert("Notification Tapped", e.data, "Done");
});
}
}
- Implement Command to trigger a local notification
var notification = new NotificationRequest
{
NotificationId = 100,
Title = "Test",
Description = "Test Description",
ReturningData = "Dummy data", // Returning data when tapped on notification.
NotifyTime = DateTime.Now.AddSeconds(30) // Used for Scheduling local notification, if not specified notification will show immediately.
};
NotificationCenter.Current.Show(notification);
- Result
- If the app is running while notification is tapped, the app seems like relaunched, or maybe MainPage was launched again.
- If the app is not running while notification is tapped, the app will be launched and nothing else happened.
Expected behavior
- If the app is running while notification is tapped, the event should be triggered.
- If the app is not running while notification is tapped, the app will be launched and the event should be triggered.
Screenshots N/A
Platform (please complete the following information):
- OS: Both Android 10 and 11
- Version: Both 29 and 30 (Target Android version)
Smartphone (please complete the following information):
- Device: Android Emulator
- OS: Tested on Android 8.1 and Android 9.0
- Version: 27/28
Additional context N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Tap on notification restart application and ...
I want to use NotificationCenter.Current.NotificationTapped event but on Android device event is not triggered. On iOS device, it work's.
Read more >Struggling to get Scheduled Notifications to work in ...
I've tried everything, the SCHEDULED notifications are just not coming up. I've followed this tutorial to the minutest details.
Read more >Untitled
Notification click in Android(Xamarin Forms) - Stack Overflow WebJun 1, ... LocalNotification NotificationTapped event does not work with Prism.DryIoc.Forms ...
Read more >Local Push Notifications in Xamarin.Forms - YouTube
With local notifications you can draw users back to your application or notify them of something. You can schedule notifications in advance ...
Read more >Plugin.LocalNotification 10.1.8
The local notification plugin provides a way to show local notifications from Xamarin and MAUI apps.
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 Free
Top 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
@maxchu92 Documentation updated
@maxchu92 can you have look at https://github.com/thudugala/Plugin.LocalNotification/wiki/Getting-NotificationTapped-to-work-with-splash-screen