Huawei Xamarin SDK Setup
OneSignal Huawei Xamarin Setup Guide
1. Xamarin OneSignal SDK Setup
Follow the Xamarin SDK Setup instructions.
2. Huawei Setup
- 2.1 Preparing the Development Environment
See Huawei's Preparing the Development Environment following each step under Preparations.
3. Create and Integrate Android Binding Libs
- 3.1 Creating Android Binding Libs
- After creating the binding libs, they must added as references

- 3.2 Integrating Android Binding Libs
- Result of adding the binding libs as references in the project

4. Using HMS Core SDK in Android App
- 4.1 Integrate HMS Core SDK
- Example package structure for
agconnect-services.json
,MainActivity.cs
, andHmsLazyInputStream.cs

MainActivity.cs
code snippet for setting HMS configuration usingHmsLazyInputStream.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 parsingagconnect-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
- Keystore Signing Certificate for Visual Studio
- Huawei Signing Certificate Usage
- You may need to create a debug or release keystore signature (choose the correct app build path,
debug
orrelease
) so that a6003
error is avoided when registering for HuaweipushToken
with the OneSignal SDK.
- You may need to create a debug or release keystore signature (choose the correct app build path,
Updated almost 2 years ago