Domanda

I have developed an application that have integrate google ad-mob ads service using new google play service so when i am implement in my project there some issue of not showing banner ads

my code is here.

Layout file

<?xml version="1.0" encoding="utf-8"?>

<ProgressBar
    android:id="@+id/ProgressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="5dp"
    android:layout_gravity="center" />

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="4"></WebView>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="*************" />

Manifest file

 <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
È stato utile?

Soluzione 2

You actually have to put in a request in your code, something like this:

AdView adView = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder().build();
adView.loadAd(request);

Otherwise it just takes up layout space, but doesn't do anything. Not sure why they forced added code with the Google Play Services version of Admob, but they do, so...

Note that you only need to do this once, after you've added this it will auto-reload them according to your Admob settings.

Altri suggerimenti

If you have padding left or right in your parent layout remove it and try again! I had the same problem with you and I just solve it with that trick....you can see following code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


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

adview = (AdView) findViewById(R.id.ad);
        adview.loadAd(new AdRequest());

and in Manifest.xml

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top