Admob ads not showing
I made a simple app and added an ad to it, but it doesn't show up on the device.
and there are no errors in my code:
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<com.google.android.gms.ads.AdView
xmlns:app="http://schemas.android.com/apk/libs/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="66dp"
ads:adSize="BANNER"
ads:adUnitId="ad_ip" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" ></uses-permission>
<meta-data
android:name="com.google.android.gms.version"
android:value="4.3.23" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
source to share
I think the problem is here
<com.google.android.gms.ads.AdView
xmlns:app="http://schemas.android.com/apk/libs/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="66dp"
ads:adSize="BANNER"
ads:adUnitId="ad_ip" >
1) The xmlns attribute should be like this and in my case I put it in the root tag of the xml file.
xmlns:ads="http://schemas.android.com/apk/res-auto"
2) Check you have provided the actual adUnitId from admob account.
Hope this helps you, if any other problem you can ask.
source to share
In the beginning, I made the same mistake, I was only using the xml file and not loading the view into my activity. So just put this inisde into action:
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
source to share
You are importing the wrong attribute xmlns
inside your declaration (it belongs to legacy admob ):
<com.google.android.gms.ads.AdView
xmlns:app="http://schemas.android.com/apk/libs/com.google.ads"
you should only use the following, which applies to AdMob for Google Play:
xmlns:ads="http://schemas.android.com/apk/res-auto"
==> remove invalid attribute xmlns
source to share
try it
XML:
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="66dp"
ads:adSize="BANNER"
ads:adUnitId="your key ID"
ads:loadAdOnCreate="true"/>
Add the following code to your manifest:
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
Hope this helps you.
source to share