shinyorg / shiny

.NET Framework for Backgrounding & Device Hardware Services (iOS, Android, & Catalyst)
https://shinylib.net
MIT License
1.44k stars 227 forks source link

[Bug]: Push Notification IntentFilter on Android is not working #1315

Closed LarryOlsen closed 1 year ago

LarryOlsen commented 1 year ago

Component/Nuget

Push - Azure Notification Hub (Shiny.Push.AzureNotificationHubs)

What operating system(s) are effected?

Version(s) of Operation Systems

Android 13

Hosting Model

Steps To Reproduce

  1. Run the ShinyPushTest project on an Android device.
  2. Tap Register.
  3. Minimize the app and send a push notification, such as: { "notification": { "title": "New Activity", "body": "A new activity is ready for review", "click_action": "SHINY_PUSH_NOTIFICATION_CLICK" } }
  4. The push notification appears on the Android device, however when tapped nothing happens.

Expected Behavior

When a push notification is tapped while the app is in the background or closed, the app should be opened and OnEntry should be called.

Actual Behavior

When a push notification is tapped while the app is in the background or closed, nothing happens.

Exception or Log output

No response

Code Sample

https://github.com/LarryOlsen/ShinyPushTest

Code of Conduct

aritchie commented 1 year ago

That's not where the click_action goes in the payload. Please review the firebase documentation. This case was just recently tested and works fine

MGohil commented 1 year ago

You need to set Categories too in the intent filter of your MainActiity. [IntentFilter(new[] { ShinyPushIntents.NotificationClickAction }, Categories = new[] { "android.intent.category.DEFAULT" })]

Also, in your OnCreate method, as a work around call this: Host.Lifecycle.OnNewIntent(this, this.Intent); This will call the OnEntry method when your app is Freshly launched by Push notification.

aritchie commented 1 year ago

@MGohil This is a beta. Please don't advertise workarounds as it will eventually be tested and fixed. I have not reproduced the issue with your workaround yet anyhow. The fact is that the push payload on this issue is wrong

LarryOlsen commented 1 year ago

I think the payload is correct. I am sending it through Azure Notification Hubs. Everything I've researched indicates that the payload for Azure Notification Hubs to Android should contain the AndroidConfig JSON (https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidConfig), which includes an AndroidNotification (https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidNotification) and optionally Data.

If I send the same payload, but leave out the click_action, then the app is opened when I tap the push notification. However, when including the click_action the app is NOT opened when the push notification is tapped. This indicates to me that the property is in the right location, but something is causing it to fail.

In the Application Output, I see these errors when tapping the push notification:

[FirebaseMessaging] Unable to log event: analytics library is missing
[FirebaseMessaging] Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
aritchie commented 1 year ago

The log is telling you the issue though. I don't create a default channel with push for you. I don't have a good answer to this and it isn't something I've documented yet because it is something that is still being considered how best to handle.

LarryOlsen commented 1 year ago

You need to set Categories too in the intent filter of your MainActiity. [IntentFilter(new[] { ShinyPushIntents.NotificationClickAction }, Categories = new[] { "android.intent.category.DEFAULT" })]

Also, in your OnCreate method, as a work around call this: Host.Lifecycle.OnNewIntent(this, this.Intent); This will call the OnEntry method when your app is Freshly launched by Push notification.

@MGohil that solved the issue, thank you!

The log entry was not the issue. It is just a warning. Android uses a channel named "Miscellaneous" if a default isn't specified.

aritchie commented 1 year ago

Categories has been added to the docs and templates