Reputation: 37
Here is my Activity class
public class MainActivity extends Activity { private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("Ad-ID");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView)findViewById(R.id.adView);
// Request for Ads
AdRequest.Builder adRequestBuilder=new AdRequest.Builder();
// Add a test device to show Test Ads
adRequestBuilder .addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adRequestBuilder.addTestDevice("abcd").build();
// Load ads into Banner Ads
//adView.setAdUnitId("Ad-ID");
adView.loadAd(adRequestBuilder.build());
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}//end of onCreate
protected void displayInterstitial() {
// TODO Auto-generated method stub
if (interstitial.isLoaded()) {
interstitial.show();
}
}
This is my simple XML Layout
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="Ad-ID" />
I tried running the application there is no error shown and I am not able to seen any sample ad's in my layout when I run it.
Please let me know where was I mistaken.
Upvotes: 1
Views: 742
Reputation: 15333
Ad Unit Id
in your code and xml file.adRequestBuilder.addTestDevice("abcd").build();
Here abcd
is not a vaild device id. If you are running your app on a real device then in Logcat
you will find its device id.You will have to put that id here in spite of abcd
.
In Logcat you will get a line saying,
To get test ads on this device, call adRequest.addTestDevice("SOME_ID_HERE");
You will have to put this id shown here in your code.
Upvotes: 2