Huawei Map Kit - 在 Xamarin.Android 中的 GetMapAsync() 之后未调用 OnMapReady()
Huawei Map Kit - OnMapReady() not called after GetMapAsync() in Xamarin.Android
我正在将 Huawei Kit 集成到我的应用程序中,但我很挣扎,因为它根本不调用 OnMapReady
:
这是我的代码:
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();
}
}
这是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)
{
}
这是我的属性:
<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" />
知道为什么它不起作用吗?
我发现你必须调试它,因为你必须有华为设备才能测试。值得庆幸的是,华为有一些远程设备可以用来测试。
遗憾的是,Visual Studio没有直接支持。
is it possible that your team creates some examples in GitHub?
你可以参考这个Docs。它包含一个演示项目,演示 Xamarin.Android.
地图插件的用法
更新:您也可以查看GitHub中的演示。
is there any way that in the future we could debug the Xamarin apps using the cloud or any alternative images for them?
感谢您的反馈,我们会将此反馈给产品部门。
目前,作为替代方案,您可以将其打包到 APK 中,然后 运行 使用 Toolkit。
更多详情,请参考this Docs。
我正在将 Huawei Kit 集成到我的应用程序中,但我很挣扎,因为它根本不调用 OnMapReady
:
这是我的代码:
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();
}
}
这是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)
{
}
这是我的属性:
<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" />
知道为什么它不起作用吗?
我发现你必须调试它,因为你必须有华为设备才能测试。值得庆幸的是,华为有一些远程设备可以用来测试。
遗憾的是,Visual Studio没有直接支持。
is it possible that your team creates some examples in GitHub?
你可以参考这个Docs。它包含一个演示项目,演示 Xamarin.Android.
地图插件的用法更新:您也可以查看GitHub中的演示。
is there any way that in the future we could debug the Xamarin apps using the cloud or any alternative images for them?
感谢您的反馈,我们会将此反馈给产品部门。
目前,作为替代方案,您可以将其打包到 APK 中,然后 运行 使用 Toolkit。
更多详情,请参考this Docs。