Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get test ad Banners and test Interstitial ads working for adMob?
    primarykey
    data
    text
    <p>I am trying to setup adMob ads. I have two questions:</p> <p>1) Am I using adListener interface correctly? 2) How come I am unable to see ad Interstitials?</p> <p>Lets start with the adListener. As far as what I understood from the instructions, adListener is an interface. So I created an interface.</p> <pre><code>import com.google.ads.AdRequest; import com.google.android.gms.ads.AdView; public interface AdListener { public void onReceiveAd(AdView ad); public void onFailedToReceiveAd(AdView ad, AdRequest.ErrorCode error); public void onPresentScreen(AdView ad); public void onDismissScreen(AdView ad); public void onLeaveApplication(AdView ad); } </code></pre> <p>Then in my main class I implemented AdListener, and once I did I was prompted to add unimplemented methods (all the methods from the interface).</p> <pre><code>public class MainActivity extends Activity implements AdListener { // other code for the body (here). Just showing the methods and implement @Override public void onReceiveAd(AdView ad) { Log.d(TAG, "onReceiveAd"); Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show(); } @Override public void onFailedToReceiveAd(AdView ad, ErrorCode error) { Log.d(TAG, "onFailedToReceiveAd"); Toast.makeText(this, "onFailedToReceiveAd", Toast.LENGTH_SHORT).show(); } @Override public void onPresentScreen(AdView ad) { Log.d(TAG, "onPresentScreen"); } @Override public void onDismissScreen(AdView ad) { Log.d(TAG, "onDismissScreen"); } @Override public void onLeaveApplication(AdView ad) { Log.d(TAG, "onLeaveApplication"); } } </code></pre> <p>My reason for thinking this does nothing is that I am not receiving my logs. I added toasts to double confirm I was not missing something. I think there is another step I am missing for this to work.</p> <p>Now for the ads part. I thought I followed the instructions well, and my banners work in fact. But my ad interstitials do not work. This is what I have for the banners and the interstitials.</p> <p>Starting with code snippet from my xml for the banner</p> <pre><code>&lt;com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="I_ADDED_CORRECT_ADUNIT_ID" ads:adSize="BANNER" /&gt; </code></pre> <p>In my main Activity, I have the following code. Again, I want to see test ads: </p> <pre><code> // setup ad banner and interstitial final TelephonyManager tm = (TelephonyManager)getBaseContext() .getSystemService(Context.TELEPHONY_SERVICE); String testDeviceId = tm.getDeviceId(); Log.d(TAG, "testDeviceId retrieved(" + testDeviceId + ")"); // create interstitial interstitial = new InterstitialAd(this); interstitial.setAdUnitId("I_ADDED_CORRECT_ADUNIT_ID"); // ad banner adView = (AdView)this.findViewById(R.id.adView); // request test interstitial ads AdRequest adRequestInterstitial = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(testDeviceId) .build(); // request test banner ads AdRequest adRequestBanner = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(testDeviceId) .build(); //load interstitial ads interstitial.loadAd(adRequestInterstitial); displayInterstitial(); // load banner ads adView.loadAd(adRequestBanner); //NOTE: the above code is all in onCreate(). //diaplayInterstitial is outside of onCreate() public void displayInterstitial() { if (interstitial.isLoaded()) { Log.d(TAG, "displayInterstitial()"); interstitial.show(); } } </code></pre> <p>Lets see what else to tell you? Awww, yes! I also have the permissions already set in the manifest. Permissions = INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, READ_PHONE_STATE.</p> <p>I went to project properties and added the google-play-services_lib</p> <p>This is my whole setup! I have tried a number of things, because I had some 'feelings' about what may be the issue. First, I thought that maybe test ad banners and test ad interstitials cannot be requested at the same time. So I moved interstitial code to onStart(). But then, I was not sure if this was necessary, beneficial or worse (and it did not work!). My second thought was that everything works fine, and once I publish my app all will be good. But regardless, my logs are not working for the AdListener. If I can get that going, I think I can start verifying with more confidence of what is going on.</p> <p>Thank you in advance for your help.</p> <p>Log SS <img src="https://i.stack.imgur.com/Rq5pP.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload