2

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?

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
  • hi Federico,Based on the information provided above, it is difficult to reproduce the problem. Can you pls provide the run log for us to check this issue? – zhangxaochen Jul 20 '21 at 02:37
  • 1
    Hi @shirley, I was able to fix it. The issue is that you have to run it on a Huawei device (not say anywhere). Now, I have two suggestions, is it possible that your team creates some examples in GitHub? They are more readable by coders. Also, is there any way that in the future we could debug the Xamarin apps using the cloud or any alternative images for them? Also, is there any way to give feedback to the Maps Team? Because the icons are too small. Thanks. – Federico Navarrete Jul 20 '21 at 09:01
  • hi @Federico,glad to hear that the problem has been resolved.About the other two questions,I post my answer below,pls kindly refer that. – zhangxaochen Jul 20 '21 at 09:31

2 Answers2

2

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.

Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
0

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.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • 1
    Hi, thanks for your answer but I use Visual Studio, not Android Studio. My issue was with Xamarin.Android and the future .NET for Android :). Please check if it's possible ;). https://visualstudio.microsoft.com/ – Federico Navarrete Jul 20 '21 at 10:13
  • 1
    Also, is it possible to move the example to GitHub? As app developers, we tend to search them there more often. Thanks. – Federico Navarrete Jul 20 '21 at 10:14
  • 1
    Also, I have another feedback for the maps team. If there is a map running in a fragment from a **BottomNavigationView** using the **MapView** option (I never tried the other option because it involves too many changes), it causes a lot of trouble. It crashes if you do click twice on the same icon, it creates odd behaviors if you are restoring the tab. I never experienced these issues with Google Maps and my changes were pretty much to adapt the current app to Petal Maps. – Federico Navarrete Jul 20 '21 at 10:18
  • 1
    @FedericoNavarrete, I have reported your requirements to the product department, But currently Toolkit does not have plan to support Xamarin :( I'll let you know if there's a plan in the future. – zhangxaochen Jul 21 '21 at 02:13
  • 1
    For your second question, I've added the GitHub link to the answer, please kindly refer. – zhangxaochen Jul 21 '21 at 02:18
  • As for the last question you asked, Thanks for your feedback, but based on your description i cannot confirm the cause of the issue. :( You may can ask a new question, tagged with [huawei-mobile-services]and post some pictures, and we will send it to the R&D team to see whether the problem can be reproduced. – zhangxaochen Jul 21 '21 at 02:29
  • Hi, we don't really need cloud debugging (this is a nice to have) but is it possible to get some Huawei images and configure them as an emulator? If we can do that, we can accomplish a similar goal just using a different option :). – Federico Navarrete Jul 21 '21 at 05:29
  • 1
    @FedericoNavarrete,According to the team,We do plan to support local emulator in the future.The specific release time is not clear yet, i will let you know when it's released. – zhangxaochen Jul 21 '21 at 06:21