I've been trying to integrate express native ads to my application. In the express native ads documentation I've read that they work best when displayed with FULL_WIDTH ad size. I tried to set my ad size to FULL_WIDTH but it fails with IllegalStateException:
Caused by: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
Here is my xml code:
<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="FULL_WIDTH"
ads:adUnitId="@string/native_ad_unit"/>
The ad unit is correct, it works with other ad sizes like 320x150 etc.
Is there something wrong with my implementation?
Cheers
I found a solution, it will work if you use it like this:
<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="FULL_WIDTHx80"
ads:adUnitId="@string/native_ad_unit"/>
You can only set it programmatically. Here is an excerpt from the documentation:
Publishers can also use the FULL_WIDTH constant when programmatically creating an AdSize for a NativeExpressAdView. In this case, the ad will occupy the entire width of the device screen.
Source: https://firebase.google.com/docs/admob/android/native-express#nativeexpressadview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With