question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin.LocalNotification NotificationTapped event does not work with Prism.DryIoc.Forms on Android

See original GitHub issue

Describe 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

  1. Install NuGet Package of Plugin.LocalNotification [https://github.com/thudugala/Plugin.LocalNotification]
  2. 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);
	}
}
  1. 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");
		});
	}
}
  1. 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);
  1. 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found