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

Viewed 359

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?

2 Answers

I found that you must debug it because you must have a Huawei device to test. Thankfully, Huawei has some remote devices that you can use for testing.

preview1

preview2

Sadly, there is no direct support for Visual Studio.

is it possible that your team creates some examples in GitHub?

You can refer to this Docs. It contains a demo project that demonstrates the usage of Map Plugin for Xamarin.Android.

Update:You can also check the demo in GitHub.

is there any way that in the future we could debug the Xamarin apps using the cloud or any alternative images for them?

Thank you for your feedback, we will send this back to the product department.

And currently, As an alternative, you can pack it into an APK and run it using Toolkit.

enter image description here

For more details,you can refer to this Docs.

Related