How to know if UnifiedNativeAd is NativeAppInstallAd or NativeContentAd?

Viewed 608
1 Answers

Use UnifiedNativeAdView adView as layout root of native ad, you can judge from some getter of UnifiedNativeAd nativeAd and inject the value:

    if (nativeAd.getStore() == null) adView.getStoreView().setVisibility(View.INVISIBLE);              
    else {
        adView.getStoreView().setVisibility(View.VISIBLE);
        ((TextView) adView.getStoreView()).setText(nativeAd.getStore());
    }

    if (nativeAd.getStarRating() == null) adView.getStarRatingView().setVisibility(View.INVISIBLE);
    else {
        ((RatingBar) adView.getStarRatingView()).setRating(nativeAd.getStarRating().floatValue());
        adView.getStarRatingView().setVisibility(View.VISIBLE);
    }

    VideoController vc = nativeAd.getVideoController();
    if (vc.hasVideoContent()) { Log.d("TAG", "has video"); }

The code above is a part of google admob example project: googleads / googleads-mobile-android-examples, you could clone it and reset to earlier commit, it would really help.

Related