You can create an app in AppGallery Connect. Then AppGallery Connect will automatically generate basic configuration information for it.






Create a Xamarin project in Visual Studio. The package name of the created app must be the same as that entered in AppGallery Connect.
Open Visual Studio and click Create a new project to create a Xamarin project.





using System;
using System.IO;
using Android.Content;
using Android.Util;
using Huawei.Agconnect.Config;
namespace agcdemo
{
public class HmsLazyInputStream : LazyInputStream
{
public HmsLazyInputStream(Context context)
: base(context)
{
}
public override Stream Get(Context context)
{
try
{
return context.Assets.Open("agconnect-services.json");
}
catch (Exception e)
{
Log.Error("Hms", $"Failed to get input stream" + e.Message);
return null;
}
}
}
}
d) Repeat a and b to create a class named XamarinCustomProvider.cs, which inherits from ContentProvider and reads the agconnect-services.json file before the app launch. Specify the class as a content provider, and set its authorities and InitOrder attributes.using System;
using Android.Content;
using Android.Database;
using Huawei.Agconnect.Config;
namespace agcdemo
{
[ContentProvider(new string[] {"APP_PACKAGE_NAME.XamarinCustomProvider"},InitOrder =99)]
public class XamarinCustomProvider : ContentProvider
{
public override int Delete(Android.Net.Uri uri, string selection, string[] selectionArgs)
{
throw new NotImplementedException();
}
public override string GetType(Android.Net.Uri uri)
{
throw new NotImplementedException();
}
public override Android.Net.Uri Insert(Android.Net.Uri uri, ContentValues values)
{
throw new NotImplementedException();
}
public override bool OnCreate()
{
AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(Context);
config.OverlayWith(new HmsLazyInputStream(Context));
return false;
}
public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder)
{
throw new NotImplementedException();
}
public override int Update(Android.Net.Uri uri, ContentValues values, string selection, string[] selectionArgs)
{
throw new NotImplementedException();
}
}
}


