我正在将华为套件集成到我的应用程序中,但我很挣扎,因为它根本不调用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();
}
}
这是活动:
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" />
知道为什么它不起作用吗?