My Xamarin. Android приложение вылетает на некоторых устройствах Stacktrace сообщает MyUnifiedNativeAd.OnUnifiedNativeAdLoaded (Android .Gms.Ads.Formats.UnifiedNativeAd ad)
Вот stacktrace
MyUnifiedNativeAd.OnUnifiedNativeAdLoaded (Android.Gms.Ads.Formats.UnifiedNativeAd ad)
UnifiedNativeAd+IOnUnifiedNativeAdLoadedListenerInvoker.n_OnUnifiedNativeAdLoaded_Lcom_google_android_gms_ads_formats_UnifiedNativeAd_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_ad)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.26(intptr,intptr,intptr)
Вот мой код, в котором я раздуваю и инициализирую слушателя
UnifiedNativeAdView adView = (UnifiedNativeAdView)LayoutInflater.Inflate(Resource.Layout.ad_unified, null);
FrameLayout frameLayout = inflated.FindViewById<FrameLayout>(Resource.Id.frameLayout1);
var a = new MyUnifiedNativeAd(adView, frameLayout);
AdLoader adLoader = new AdLoader.Builder(Context, Resources.GetString(Resource.String.ad_unit_id))
.ForUnifiedNativeAd(a)
.WithAdListener(new MyAdListener())
.Build();
adLoader.LoadAd(new AdRequest.Builder().Build());
Это класс слушателя, который реализует интерфейс IOnUnifiedNativeAdLoadedListener
class MyUnifiedNativeAd : Java.Lang.Object, IOnUnifiedNativeAdLoadedListener
{
UnifiedNativeAdView AdView = null;
FrameLayout frame = null;
public MyUnifiedNativeAd( UnifiedNativeAdView adv, FrameLayout f)
{
AdView = adv;
frame = f;
}
public void OnUnifiedNativeAdLoaded(UnifiedNativeAd ad)
{
if (ad is null)
return;
MediaView mv = AdView.FindViewById<MediaView>(Resource.Id.ad_media);
TextView advertiser = AdView.FindViewById<TextView>(Resource.Id.ad_advertiser);
TextView headline = AdView.FindViewById<TextView>(Resource.Id.ad_headline);
ImageView img = AdView.FindViewById<ImageView>(Resource.Id.ad_app_icon);
TextView body = AdView.FindViewById<TextView>(Resource.Id.ad_body);
RatingBar rating = AdView.FindViewById<RatingBar>(Resource.Id.ad_stars);
TextView price = AdView.FindViewById<TextView>(Resource.Id.ad_price);
TextView store = AdView.FindViewById<TextView>(Resource.Id.ad_store);
Button action = AdView.FindViewById<Button>(Resource.Id.ad_call_to_action);
List<View> v = new List<View>() { mv, advertiser, headline, img, body, rating, price, store, action };
action.Text = ad.CallToAction;
store.Text = ad.Store;
price.Text = ad.Price;
rating.NumStars = ad.StarRating is null ? 0 : ad.StarRating.IntValue();
body.Text = ad.Body;
img.SetImageDrawable(ad.Icon.Drawable);
headline.Text = ad.Headline;
advertiser.Text = ad.Advertiser;
AdView.MediaView = mv;
AdView.SetNativeAd(ad);
frame.RemoveAllViews();
frame.AddView(AdView);
}
}