getting an ad response. ErrorCode: 1 - android

I am testing my application in device it is showing the error in debug logcat what is this error and how to solve this?
The error is
There was a problem getting an ad response. ErrorCode: 1
my xml code is
<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"
android:background="#color/accent_material_light"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
my code to display the ads is
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
and in manifest file I am adding.the code is working fine but the ads are not displaying I am testing it on my device
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!--This meta-data tag is required to use Google Play Services.-->
<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"
android:theme="#android:style/Theme.Translucent" />

Try to use Ad unit ID.
You may mistakenly use the APP ID or PUBLISHER ID.. (Like my mistake)
Sample Ad Unit ID (it contains xxxxx/xxxxx)
ca-app-pub-9390048287444061/3221111032 - correct one
Sample App ID (it contains xxxxx~xxxxx)
ca-app-pub-9390048287444061~1222077830 - wrong one

the issue is solved by adding the ad-Unit Id Other than publisher id and adding the test device id through AdRequest

as you say,
you have done all attempt write all code perfectly in manifest as well as build.gradle file.
this same problem was to me.
so after that i have resolved this problem by correcting my ad-mob unit id and also
it was written in uppercase.so i modify it to lowercase and works perfectly.
This works for me.Hope this help others too!!.

I had the same problem.
I believe Error Code 1 is due to many different reasons, but mine was wrong adSize. I set up for NativeAdExpress, but was giving wrong dimensions in XML, MEDIUM_RECTANGLE worked for my NativeAdExpress view.

try adding below code to you gradle file.
compile 'com.google.android.gms:play-services-ads:8.1.0'

Related

Failed to load ad (Error 1)

Have been searching for hours on google, but still without success.
I always get the Error Message and the adBanner doesnt load:
There was a problem getting an ad response. ErrorCode: 1
Failed to load ad: 1
build.gradle
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
Android Manifest
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent"
/>
layout
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_marginTop="20dip"
ads:adUnitId="pub-*****************"
android:layout_below="#+id/middle"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
activity (imports)
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
activity
AdView adView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
permissions are also added
ty for your help in advance
Error 1 means the ID is wrong.
Admob gives you a number like this and is the general ID, with ~ :
ca-app-pub-9611919736642270~3440171884
And the ads id with / is to the request;
ca-app-pub-9611919736642270/3440171834
I got this error on Adaptive banner for android
I/Ads: Ad failed to load : 1
because of this line
width = (int)( metrics.widthPixels);
Solution
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
width = (int)( metrics.widthPixels/metrics.density);
AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mContext, width);
I hope it helps someone.
The error code 1 refers to Invalid request.
//(public static final int ERROR_CODE_INVALID_REQUEST
The ad request was invalid; for instance, the ad unit ID was incorrect.
Constant Value: 1) //
Thus you must check whether your Ad-Ids are defined at right place. Don't put banner ads id to interestial ads and vice versa. for other error codes just take a look on this link:
https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_NO_FILL
Add the following meta data to AndroidManifest.xml file:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />

AdMob ErrorCode 0 mostly

I have a problem with my Android App which I'm trying to add ads for, the weird thing is that the ad loads perfectly on the first activity, but none of the others. I've followed the instructions on https://developers.google.com/admob/android/existing-app, but to no avail it still only works with the first activity. I have a different Ad Unit ID for each activity that I have ads on as well, and have copy-pasted them from the website to avoid mistakes, and have removed all whitespace.
The response I get is:
There was a problem getting an ad response. ErrorCode: 0
Failed to load ad: 0
I've done research on why I'd get this response from AdMob, and I've tried the solutions I have found, they are to add the correct version (and check for updates) of the Google Play Services to my build.gradle file, to add the version to my manifest file, I am running it on the stock rom that came with a real phone (LG G4 running Lollipop) I even tried on a different phone which was also running stock Android to get the same result.
The way I load the ads onto my page is with this code:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
This is the same on every activity with ads on it.
This is a snippet of my Manifest file:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Finally, this is the ad snippet of my layout file, which is also the same in all of my layouts:
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_home">
</com.google.android.gms.ads.AdView>
I have a string resource for each different activity Ad Unit ID.
It just started working, I changed nothing. Maybe there was a problem building it before? Who knows, thanks for all the help though guys.
AdView adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
Whenever you load Admob banner ad this gives 0 error.This is just because you have not signed it.you must load and show Test admob Banner ad.if test ad is servering perfectly then you will get right ad in signed apk.0 error may be just because you have not signed apk
did you added this line in your manifest file?
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
or try like this
Open your adMob account and create new sets of keys,and put this keys(banner/interstitial)in your project.this is happens to me once i fixed like this,try this solution. or still issues create new app (just change the name) in adMob and create new keys

Google Play Ads not working android 4.4 (required xml attribute ads:adSize was missing)

My application was working with android 4.2 and using Admob x.x.x.jar file few days back.
i just configured android sdk 4.4 and i noticed Google play ads are not longer working, also found it should be upgraded as well so what i did following:
Before My XML Was:
<com.google.android.gms.ads.AdView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
ads:adSize="BANNER"
ads:adUnitId="asdadadasddas"
/>
Today I updated it
<com.google.android.gms.ads.AdView android:id="#+id/adView"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="asdadadasddas"
ads:adSize="BANNER"
/>
My Manifest
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
values => Integer.xml
<integer name="google_play_services_version">5089034</integer>
and it give me following error
Note: I am not using any java code to display it is that necessary?
any help would be appreciated.
I appreciate answers of all developers actually i solved this problem by combining the answers of all so i would like to enter steps here that might help others.
XML Layout:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-***"
ads:adSize="BANNER"
/>
Two mistakes in my code were:
1) xmlns:ads value was wrong & this mistake pointed out by donfuxx
2) i was using old AdUnitId with following format: a15220c7a5f3775 but in latest AdMob its format is entirely different as used in above example.
Note:
If you use old "ads:adUnitId" it will show blank ad and this was the case with me.
Javacode
Java code is also required
AdRequest adRequest = new AdRequest.Builder()
.build();
AdView adView = (AdView) view.findViewById(R.id.adView);
adView.loadAd(adRequest);
Then again i found another error:
Class not found exception although i had imported the Google Play project in my application.
Then i found an article in which it was mentioned copy Google Play Jar inside your "libs" folder and it will be automatically included in your android private libraries to resolve this issue.
Final Issue
No need to put value in integer.xml inside your app because when you include Google play services project inside your app, it will automatically pick version value out of it in your manifest file.
So these were the issues i faced during migration of adMob and will help others to implement it quickly.
You can still use ads:adSize xml attribute!
However, your xml namespace setting is wrong in the adview element, because it refers to the legacy admob:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
but since you already use the google play admob, you should use:
xmlns:ads="http://schemas.android.com/apk/res-auto"
that is why the ads: attributes were not recognized.
More infos see the official admob migration guide.
You should no longer be setting your adUnitId/adSize in the layout. Instead do:
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
Layout:
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
And finally,
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("XXXXXXXXXXXXXXXXXXXX")
.build();
adView.loadAd(adRequest);

AdMob not getting real ads in Android

I am working for Admob in Android and I got success in getting test ad. But When I Change My Test UnitId To To Live UnitID something like this "/5479/ctv.abcd.ca/myid" I am getting the warning like "is your unit id correct ?". and also i commented the lines for adding test devices. but still i am not seeing any real adds.
Any Ideas..... Any Better Solution..
LinearLayout lladView = (LinearLayout) inflater.inflate(R.layout.addmob, null);
AdView adView = (AdView) lladView.findViewById(R.id.adView1);
adView.loadAd(new AdRequest());
and my xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="/5479/ctv.abcd.ca/myid"
ads:loadAdOnCreate="true"/>
</LinearLayout>
You seem to be providing the wrong adUnitId. You have to specify your AdMob publisher ID that can be obtained from the AdMob Sites & Apps -> [Your App Name] -> Manage Settings.

Integrating admob into Android app

Been having some trouble trying to integrate the admob sdk into my application to display ads. Im using the AdmobSDK version 4.1.0. I've read loads of posts and there seems to be lacking some decent documentation and many discussions on the topic including http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5?pli=1 So far my layout is..
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true">
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_PUB_CODE"
ads:adSize="BANNER"/>
</LinearLayout>
</ScrollView>
my androidmanifest.xml contains...
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>
<meta-data android:value="MY_PUBLISHER_ID" android:name="ADMOB_PUBLISHER_ID"></meta-data>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
EDIT, UPDATE:
Ok i seem to have gotten admob working on my HTC by adding,
AdView ad = (AdView) findViewById(R.id.ad);
AdRequest r = new AdRequest()
r.addTestDevice("X3XFX518X7DE1FD879XA5XXAX1AX8BXX");
ad.loadAd(r);
however i only recieve a test banner, stating im ready to explore the google app galaxy. When i remove the "addTestDevice" method, the banner/ad does not show up atal and in the log i recieve, "ad not recieved due to lack of inventory" .. Anyone sheed some light on this?
thanks for the help so far!
To your comment, I use this and it works quite well for me. The size is the second param of the AdView constructor.
ad = new AdView(this, AdSize.BANNER, "<ID>");
LinearLayout layout = (LinearLayout) findViewById(R.id.main_admob_layout);
// Add the adView to it
layout.addView(ad);
AdRequest request = new AdRequest();
request.setTesting(TESTING_MODE);
ad.loadAd(request);

Categories

Resources