0

I'm having a hard time with AdMob.

I have an app with eleven (11) activities. I successfully created the test banner ad but I can't see the real ads. Do I have to create 11 adunits or is there a way to create a single banner that overrides the activities somehow? What is the best way?

(Users will stay in each activity for est. 5 seconds.. I don't know how useful is to have 11 different banners)

Any ideas?

Also, I would be happy, if someone give me a step by step guide for AdMob (from android studio to publish)

In all xml files:

    <com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    ads:adSize="BANNER"
    ads:adUnitId="@string/admob_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

Here is what I added to build.gradle:

    compile 'com.google.android.gms:play-services-ads:9.0.2'

And in all activities:

    AdView adView = (AdView) findViewById(R.id.adView);

    AdRequest adRequest = new AdRequest.Builder()
            .setRequestAgent("android_studio:ad_template").build();
    adView.loadAd(adRequest);
Allie Fly
  • 55
  • 1
  • 8
  • Maybe [that](http://stackoverflow.com/questions/18591724/mopub-ads-not-showing)'s the case... – Onik Dec 22 '16 at 11:17

1 Answers1

0

You can have one ad unit for an app but you have to manually add admob banner code to each activity.

In Development process you should add test device to the code. If you want to see real ads then you can escape adding test device. But Do not click these ads.

Xml Code

 <RelativeLayout
        android:id="@+id/adViewContainer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"

        />

In Activity

RelativeLayout adlayout=(RelativeLayout)findViewById(R.id.adViewContainer);
showAdmobBanner(adlayout,"AD_ID");

Banner Code

  void showAdmobBanner(RelativeLayout layout,String AdID)
    {
        com.google.android.gms.ads.AdView mAdView = new com.google.android.gms.ads.AdView(context);
        mAdView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
        mAdView.setAdUnitId(AdID);

        // Create an ad request.
        AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

        // Optionally populate the ad request builder.
        adRequestBuilder.addTestDevice(Constants.admobTestDevice);

        // Add the AdView to the view hierarchy.
        layout.addView(mAdView);

        // Start loading the ad.
        mAdView.loadAd(adRequestBuilder.build());
    }

In your code you can use it

MobileAds.initialize(getApplicationContext(), "APPID"); //In first Activity

        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
Abhishek Agarwal
  • 1,907
  • 12
  • 21
  • Ok thank you.. I already have a banner for each xml and I have a string for the adUnitId. Still nothing.. – Allie Fly Dec 22 '16 at 10:02