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

Follow these instructions if your app is distributed on the Huawei AppGallery.

Step 1. Requirements

Step 2. Setup the OneSignal Xamarin SDK

Follow the OneSignal Flutter SDK setup guide. Firebase / Google setup not required for app builds released to the Huawei AppGallery.

Step 3. Huawei Setup

3.1 Preparing the Development Environment
See Huawei's Preparing the Development Environment following each step under Preparations.

Step 4. Create and Integrate Android Binding Libs

4.1 Creating Android Binding Libs

  • After creating the binding libs, they must added as references

4.2 Integrating Android Binding Libs

  • Result of adding the binding libs as references in the project

Step 5. Using HMS Core SDK in Android App

5.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 2 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.