OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Huawei Xamarin SDK Setup

OneSignal Huawei Xamarin Setup Guide

1. Pre-Requisites

2. Create and Integrate Android Binding Libs

3. Using HMS Core SDK in Android App

  • 3.1 Integrate HMS Core SDK
  • Example package structure for agconnect-services.json, MainActivity.cs, and HmsLazyInputStream.cs
  • MainActivity.cs code snippet for setting HMS configuration using HmsLazyInputStream.cs
using Android.Content;
using Android.OS;
using Com.Huawei.Agconnect.Config;
using Com.OneSignal.Sample.Shared;
using System;

namespace Com.OneSignal.Sample.Droid
{
    [Activity(Label = "Com.OneSignal.Sample.Droid", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity
    {
    
        protected override void AttachBaseContext(Context context)
        {
            base.AttachBaseContext(context);
         
            // Read the agconnect-services.json so that the config is set for Huawei to register for a pushToken
            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(context);
            // Refer to Huawei docs or below on how to create your HmsLazyInputStream class
            config.OverlayWith(new HmsLazyInputStream(context));
        }

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            // Init OneSignal through a Shared class, easier to init for both Android and iOS applications
            SharedPush.Initialize();
        }
    }
}
  • HmsLazyInputStream.cs code snippet for parsing agconnect-services.json
using Android.Content;
using Com.Huawei.Agconnect.Config;
using System;
using System.IO;

namespace Com.OneSignal.Sample.Droid
{
    public class HmsLazyInputStream : LazyInputStream
    {
        public HmsLazyInputStream(Context context) : base(context)
        {
        }

        public override Stream Get(Context context)
        {
            try
            {
               // Trying to read agconnect-services.json file
               return context.Assets.Open("agconnect-services.json");
            }
            catch (Exception e)
            {
               // Failed to read agconnect-services.json file
               return null;
            }
        }
    }
}

Notes/Resources

  • This is an example Xamarin project integrating the binding libs for HMS Core SDK.

  • HMS error code reference to help debug logs and successfully integrate HMS Core SDK with the OneSignal SDK.

Keystore Signature

Updated 3 months ago


Huawei Xamarin SDK Setup


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.