Question

Hi I was able to add the google adMob banner, and it displayed the error messages of the meta-data, when I ran the app it self, but once I did manage to solve those problems it does not show the google ad. It shows the banner however it is empty.

I have it set so that the adView is in a different layout to the background, and it shows when the screen is tapped. The problem is that when you tap the screen it shows a banner darker area, where the banner errors were being displayed (which I assume to be the GoogleAd banner) however it shows empty. So only the area of it is darkened but displaying nothing.

Here is my MigratorisActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.migratoris_activity);

    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    final View contentView = findViewById(R.id.GIFSingle);

    // Create the adView.
    adView = new AdView(this);
    adView.setAdUnitId("a--------------");
    adView.setAdSize(AdSize.BANNER);

    // Lookup your LinearLayout assuming it's been given
    // the attribute android:id="@+id/mainLayout".
    LinearLayout layout = (LinearLayout) findViewById(R.id.fullscreen_content_controls);

    // Add the adView to it.
    layout.addView(adView);

    // Initiate a generic request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Load the adView with the ad request.
    adView.loadAd(adRequest);

This is my Manifest:

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
        <activity
            android:name="pt.quintas.migratoris.MigratorisActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

Anyone have an idea why it shows but without an ad? could it be that I have the AdMob account set to test mode?

Thank you very much for your time, Pedro

Here is the Layout

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:id="@+id/MainLayout"
    tools:context=".MigratorisActivity" >

    <!--
         The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc.
    -->

    <pt.quintas.migratoris.GIFView
        android:layout_marginLeft="0dp" 
        android:layout_gravity="center"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:id="@+id/GIFSingle">
    </pt.quintas.migratoris.GIFView>

     <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|top"
        android:textStyle="bold"
        android:textSize="10pt"
        android:padding="16dip"

        android:textColor="#ffffffff"
        android:text="You have migrated for:" />

    <TextView
        android:id="@+id/textCounter"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|bottom"
        android:textStyle="bold"
        android:textSize="10pt"
        android:padding="16dip"

        android:textColor="#ffffffff"
        android:text="" />

    <!--
         This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows.
    -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true" >

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?buttonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent" >



        </LinearLayout>
    </FrameLayout>

</FrameLayout>

I have tried to make the add work in the MainLayout and it worked I believe the problem is inflating it with the layout, it needs more space. here is the logg:

01-15 16:50:53.552: I/ApplicationPackageManager(11135): cscCountry is not German : VOD
01-15 16:50:54.002: I/Ads(11135): Use AdRequest.Builder.addTestDevice("B246DEAA33A5FAE6AF9FF0A2F44B5CBC") to get test ads on this device.
01-15 16:50:54.002: I/Ads(11135): Starting ad request.
01-15 16:50:54.002: I/webclipboard(11135): clipservice: android.sec.clipboard.ClipboardExManager@4065d018
01-15 16:50:54.012: W/Ads(11135): Not enough space to show ad. Needs 480x75, but only has 474x754
01-15 16:50:54.022: W/Ads(11135): Not enough space to show ad. Needs 480x75, but only has 474x792
01-15 16:50:54.032: W/Ads(11135): Not enough space to show ad. Needs 480x75, but only has 474x792
01-15 16:50:54.052: E/GooglePlayServicesUtil(11135): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
01-15 16:50:54.182: E/GooglePlayServicesUtil(11135): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
01-15 16:50:54.223: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:54.273: E/GooglePlayServicesUtil(11135): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
01-15 16:50:54.443: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:54.663: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:54.893: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:55.183: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:55.384: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:55.584: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:55.804: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:56.134: E/(11135): Wink AGIF Error 7 700 100 7
01-15 16:50:56.224: I/Ads(11135): Ad finished loading.
Was it helpful?

Solution

You are missing the com.google.ads.AdView in your XML file, try the following:

<com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="YOUR_ID"
        ads:refreshInterval="NUMBER_UP_TO_YOU" >
</com.google.ads.AdView>

Let me know if this helps you or not.

OTHER TIPS

I suggest adding admob in the xml layout file without adding code to src files

    <com.google.ads.AdView
  android:id="@+id/adView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  ads:adSize="BANNER"
  ads:adUnitId="YOUR_ID"
  ads:loadAdOnCreate="true"
  android:layout_alignParentBottom="true"
  ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />

and add this at the beginning of your layout file

 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

under

      xmlns:android="http://schemas.android.com/apk/res/android"

Try testing in real devices. The emulator that you are running might not have google play services

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top