Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you process push notifications received while the app is in the background? #351

Closed
1 task done
Osmosis311 opened this issue Dec 16, 2022 · 7 comments
Closed
1 task done
Assignees

Comments

@Osmosis311
Copy link

How can we help?

Is there a way to receive an event / handle a push notification that's received when my app is in the background? I'm using the OneSignal Xamarin SDK, and in the documentation it says to add a notification service extension, and inherit from this class OSRemoteNotificationReceivedHandler, but that class isn't found anywhere in the SDK.

Is there a way to do this in the Xamarin SDK?

Code of Conduct

  • I agree to follow this project's Code of Conduct
@brismithers
Copy link
Contributor

Hi @Osmosis311 apologies for the delay! The documentation for adding a NotificationServiceExtension is an iOS-specific step. There is no equivalency on Android that can be exploited by the Xamarin SDK.

Note I believe there is a path where you can create an Android native NotificationServiceExtension,it would be written in Java/Kotlin and would extend the OSRemoteNotificationReceivedHandler class you reference above. The underlying technical reason for not having a Xamarin SDK equivalent is, we have not found a way to "get into" the Xamarin environment when your app is driven through the receiving of a notification while the app is in the background/not open.

Staying within the Xamarin SDK, you are limited to the OneSignal.Default. NotificationWillShow event, which unfortunately is limited to notifications received while the app is in the foreground.

Please let me know if you have any follow up questions. Thanks!

@brismithers brismithers self-assigned this Jan 9, 2023
@brismithers
Copy link
Contributor

@Osmosis311 would you be able to share your use case for why you need to receive control when receiving a notification and your app isn't in the foreground?

@Osmosis311
Copy link
Author

Osmosis311 commented Jan 17, 2023 via email

@brismithers
Copy link
Contributor

thanks for the feedback @Osmosis311, I'll pass that along internally as a scenario to account for. Yes a generic notification receiver would work as well good thought. If you're up for it please post a version of what you did here and I can try to incorporate it as a solution into our docs.

@Tock3r
Copy link

Tock3r commented Jan 19, 2023

I need that badly too. @Osmosis311, your solution would be very helpful. :)
In my use case, security guards receive an alarm notification with status messages that they have to acknowledge. If they ignore the notification, the app will periodically remind them with a warning sound.

@Osmosis311
Copy link
Author

Here's the code for the receiver.

Add this to MainActivity.cs in the OnCreate function:

IntentFilter filter = new IntentFilter("com.google.android.c2dm.intent.RECEIVE"); RegisterReceiver(new PushReceiver(), filter);

@Tock3r
Copy link

Tock3r commented Jan 23, 2023

Awesome, it works. Thank you. I had it similar, I only registered the receiver in the launch activity and not in main :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants