Huawei Map Kit – OnMapReady() not called after GetMapAsync() in Xamarin.Android

I'm integrating the Huawei Kit in my app but I'm struggling because it doesn't call OnMapReady at all:

img2

img1

img3

img4

This is my code:

XML:

<com.huawei.hms.maps.MapView
                android:id="@+id/map"
                app:mapType="normal"
                app:liteMode="true"
                app:uiCompass="true"
                app:uiZoomControls="true"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

C#:

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;
        }
    }
}

[ContentProvider(new string[] { "tk.supernovaic.themayanroute.XamarinCustomProvider" })]
public class XamarinCustomProvider: ContentProvider
{
    public XamarinCustomProvider()
    {
    }

    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();
    }
}

This is the Activity:

        private MapView mapView;


        private const string MAPVIEW_BUNDLE_KEY = "MY_KEY";

                MapsInitializer.Initialize(Activity);
     //I tried my ID and my API id and nothing.
                MapsInitializer.SetApiKey("MY_API_FROM_THE_WEBSITE?");
                mapView = (MapView)view.FindViewById(Resource.Id.map);
                mapView.OnCreate(savedInstanceState);
                mapView.GetMapAsync(this);

        public override void OnPause()
        {
            base.OnPause();
            mapView.OnPause();
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
            mapView.OnDestroy();
        }

        public override void OnSaveInstanceState(Bundle outState)
        {
            base.OnSaveInstanceState(outState);
            Bundle mapViewBundle = outState.GetBundle(MAPVIEW_BUNDLE_KEY);
            if (mapViewBundle == null)
            {
                mapViewBundle = new Bundle();
                outState.PutBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle);
            }
            mapView.OnSaveInstanceState(mapViewBundle);
        }

        public override void OnLowMemory()
        {
            base.OnLowMemory();
            mapView.OnLowMemory();
        }

        public override void OnResume()
        {
            base.OnResume();
            mapView.OnResume();
        }

        public override void OnDestroyView()
        {
            base.OnDestroyView();
        }

        public async void OnMapReady(HuaweiMap googleMap)
        {
        }

This is my properties:

        <meta-data android:name="com.huawei.hms.client.appid" android:value="appid=MY_ID" />

    <uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA" />


Any idea why it's not working?



Read more here: https://stackoverflow.com/questions/68447982/huawei-map-kit-onmapready-not-called-after-getmapasync-in-xamarin-android

Content Attribution

This content was originally published by Federico Navarrete at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: