Intermediate: OneSignal Push Notification Integration in Xamarin (Android)

Overview

Manoj Kumar
4 min readJun 11, 2021

In this article, I will create a demo app along with the integration of OneSignal which is based on Cross platform Technology Xamarin. It provides messages that are “pushed” from a server and pop up on a user’s device, even if the app is not in running state. They are a powerful re-engagement tool meant to provide actionable and timely information to subscribers.

OneSignal Service Introduction

OneSignal is the fastest and most reliable service to send push notifications, in-app messages, and emails to your users on mobile and web, including content management platforms like WordPress and Shopify. Users can discover resources and training to implement One Signal’s SDKs.

Prerequisite

1. Xamarin Framework

2. Huawei phone

3. Visual Studio 2019

4. OneSignal Account

App Gallery Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Navigate to Project settings and download the configuration file.

3. Navigate to General Information, and then provide Data Storage location.

OneSignal SDK Integration process

1. Choose Huawei Android (HMS) and provide app name.

2. Choose Xamarin then click Next.

3. Copy your App Id.

4. Create New Push message from One Signal’s Dashboard.

5. Find Review Your Message tab, then click Send Message button.

Installing the Huawei ML NuGet package

1. Navigate to Solution Explore > Project > Right Click > Manage NuGet Packages.

2. Search on Browser Com.OneSignal and Install the package.

Xamarin App Development

1. Open Visual Studio 2019 and Create A New Project.

2. Configure Manifest file and add following permissions and tags.

3. Create Activity class with XML UI.

MainActivity.cs

This activity performs all the operation regarding Push notification.

Xamarin App Build Result

1. Navigate to Build > Build Solution.

2. Navigate to Solution Explore > Project > Right Click > Archive/View Archive to generate SHA-256 for build release and Click on Distribute.

3. Choose Archive > Distribute.

4. Choose Distribution Channel > Ad Hoc to sign apk.

5. Choose Demo keystore to release apk.

6. Build succeed and click Save.

7. Result.

Message Deliver statistics

Tips and Tricks

Notification Types-25 means OneSignal timed out waiting for a response from Huawei’s HMS to get a push token. This is most likely due to another 3rd-party HMS push SDK or your own HmsMessageService getting this event instead of OneSignal.

Conclusion

In this article, we have learned how to integrate OneSignal Push Notification in Xamarin based Android application. Developer can send OneSignal’s Push Message to users for new updates or any other information.

Thanks for reading this article. Be sure to like and comment to this article, if you found it helpful. It means a lot to me.

References

OneSignal Docs: https://documentation.onesignal.com/docs/xamarin-sdk-setup

OneSignal Developer: https://app.onesignal.com/

--

--