Do Google ads work differently than the AdMob SDK when loading ads?

I recently moved my project from the AdMob SDK to Google ads, but I’m having a slight problem with Google ads.

I have the look of an advertising banner in action, and I would dynamically customize the buttons in the layout depending on whether the ad was loaded. It worked great when I used the AdMob SDK, but now with Google ads, the banner is always reserved there with a space before loading the ad. And if the ad cannot be loaded (say, without a network), an empty view is displayed here, which is pretty ugly! That is why I would like to dynamically adjust the layout ...

Did I miss something while changing the code? Thank you for your help!

Here is a snippet of java code and layout file:

Java:

import com.google.android.gms.ads.*; ... public class MyActivity extends Activity { ... @Override public void onCreate(Bundle savedInstanceState) { ... AdView adView = (AdView)findViewById(R.id.ad); AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); } } 

XML format:

 ... <com.google.android.gms.ads.AdView android:id="@+id/ad" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adUnitId="AD_PUB_ID" ads:adSize="BANNER"/> </RelativeLayout> 
+6
source share
2 answers

You can add an AdListener and make the ad visible only when it receives the ad.

The code is as follows:

  final AdView ad = new AdView(context); ad.setAdUnitId(publisherId); ad.setAdSize(AdSize.SMART_BANNER); final AdListener listener = new AdListener() { @Override public void onAdLoaded() { ad.setVisibility(View.VISIBLE); super.onAdLoaded(); } }; ad.setAdListener(listener); ad.setVisibility(View.GONE); adParent.addView(ad); ad.loadAd(new AdRequest.Builder().build()); 

Because there is / a problem, the AdMob ad generates ANR when it is destroyed upon loss. I usually check the visibility of an ad before calling pause() or destroy() .

+9
source

Be careful because it’s against the policy of Google Ad so that the banner ad pops up like this. I received mail from Google a month ago and had to change this behavior to prevent my application from banning the use of the Play Store. Many developers receive the same mail.

0
source

All Articles