Failed to load ad (Error 1) - android

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" />

Related

Getting Invalid application ID error when using Test application ID with adMob

I am getting an error when i am trying to implement admob to my app:
java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:Invalid application ID
I am using test application ID. Here is my manifest:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544/6300978111"/>
Gradle:
implementation 'com.google.android.gms:play-services-ads:18.1.1'
Activity code
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
mAdView.loadAd(adRequest);
XML code
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
I do not understand why i am still getting Invalid application ID code. I am using test application ID
You put your Ad Unit ID in AndroidManifest.xml - which is wrong. You should add your AdMob App ID here.
Ad Unit IDs have this format:
ca-app-pub-3940256099942544/6300978111 //Test ID for a banner
AdMob App IDs have this format:
ca-app-pub-3940256099942544~3347511713 //Test App ID
Ok, seems that in manifest i have to put real application ID
You need to use a real ID in both the cases, i.e., the app ID case and also the AdUnit case. If you are in testing, then you may use test ones. But on release, use real IDs from your AdMob dashboard to get real ads when users use your app. Otherwise, the ads won't work.

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

getting an ad response. ErrorCode: 1

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'

Admob ads showing in emulator but not in real device

I have integrated admob in my app but the ads showed up in emulator but when i tried in real device it's not showing up. For integration i have added below code in AndroidManifest.xml
<!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Google Play service -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- Ad activity -->
<activity
android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
Then in my activity's layout i have added below Linearlayout to load the ad in it :
<LinearLayout
android:id="#+id/main_menu_banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:orientation="horizontal" />
Then in activity i have written below java code for integration :
/* The view to show the ad. */
private AdView adView;
/* Your ad unit id. Replace with your actual ad unit id. */
private static final String AD_UNIT_ID = "My_admob_key";
// Create an ad.
adView = new AdView(MainMenu.this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.main_menu_banner);
layout.addView(adView);
// Initiate a generic request.
AdRequest adRequest = new AdRequest.Builder().build();
// Load the adView with the ad request.
adView.loadAd(adRequest);
layout.bringToFront();
Any help would be appreciated why ads are not showing up!!!! Also you can point to any good tuto for integrating admob will also help. Thanks in advance
Add the extras as well
AdMobExtras extras = new AdMobExtras(bundle);
AdRequest adRequest = new AdRequest.Builder()
.addNetworkExtras(extras).build();
adView.loadAd(adRequest);
May be you missed adding Test device or added wrong ID, same thing happened with me as till I noticed in the Logcat this alert;
04-22 10:04:04.887 I/Ads: Use
AdRequest.Builder.addTestDevice("6612F2AEECD2A4ADBD699CFC349AB01A") to
get test ads on this device.
Once I added it, it started working fine.
In my case there were an issue with the size of the view.
So I debugged the app in Android Studio and found the right hint in the Android Monitor Tab:
Not enough space to show ad. Needs 320x150 dp, but only has 318x0 dp.
I faced the same issues when I was working on changing the targetSDKversion.
I was using a Galaxy S7 phone to test.
I manged to get it working by allocating more space for the adview.
For ads to show up, tried making the view 3:1 with
android:layout_weight="3" for upper activity (75%)
android:layout_weight="1" for adView activity (25%)
android:layout_height="0dp"

Admob ads not showing up

I am trying to implement Admob in Android and I am seeing requests coming into AdMob. However, I am not seeing the Admob ads being displayed on the Android screen in the emulator and my Android test phones as well.
As stated before, I can see the requests coming into my AdMob account. However, the content is not being shown. Is there something that needs to be enabled in my account, the main.xml, AndroidManifest.xml, or in the loading of the application?
My application configuration and code are below. Please advise on what is needed. Thanks!
AndroidManifest:
<meta-data
android:value="My Publisher ID"
android:name="ADMOB_PUBLISHER_ID" />
<activity android:name="com.admob.android.ads.AdMobActivity"/>
<receiver
android:name="com.admob.android.ads.analytics.InstallReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<meta-data
android:value="true"
android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"/>
main:
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="My Publisher ID"
ads:loadAdOnCreate="true"/>
On Create Code:
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setTesting(true);
adView.loadAd(re);
Any help is appreciated!!
Make sure that the layout the AdView is embedded in does not impose any padding on the AdView. The AdView's size has to be exactly 320x50 dip. It does not show up if it does not get enough room.
Also check the log output of your device. In Eclipse switch to the DDMS perspective, select your device and watch the LogCat output.
I had a similar issue. If you have any padding on your parent layout then you may not have enough width for the ads. If you have it in a portrait view try switching to a landscape view to see if it shows. If it does than you most likely have a width issue somewhere in your layout.
It usually takes some time for ads to start appearing via admob. This happens in the case when you have just registered on admob and started up with your first application. If the suggestions given above are taken care of and if your admob page shows a "green" status, I wont worry about it too much. Once your fill rate increases, you will start to see more and more ads.
Go to app settings on admob.com and make sure use location
data for ads is turned off if your app is not a location based app.
Use location data for ads is used to filter ads based on location and
works only on app with location permission granted. If app does not use
location permission, ads will not show.
Make sure your have filled payment details
Be sure that your Admob layout is displaying in xml view. Put your admob view inside RelativeLayout and try to use android:alignparentBottom:true
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Do our code that you want to show in xml -->
<!--Put adview in bottom of screen -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
ads:adUnitId="#string/addmob_id"
ads:loadAdOnCreate="true"
ads:testDevices="HT9CWP803129" />
</RelativeLayout>
</LinearLayout>
In your java code put these lines in onCreate method
// Load addvertisment
AdView adView = (AdView) findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder().addTestDevice("FF9CD441FA62FD456D7D571B91DD11DD").build();
adView.loadAd(adRequest);
This worked in my code, Hope it will help you too.
Be carefull with the id, there are 2 codes: the editor number (like this: pub-xxxxxxxxxxxxxxxx) and the other is the banner id (like this: ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx)
You need to use the last one, if you use the first doesnt work:)
You are using
ads:adUnitId="My Publisher ID"
replace it with
ads:adUnitId="Here AdUnitId for this app"
Note: You have to create app on Admob and you will get AdUnitId for that created app. You don't have to use Publisher ID.
I see there are two problems in your code based on what you posted:-
The <metadata> section should contain the ADMOB_APP_ID instead of your
publisher ID. This should be declared under <application> tag in
ApplicationManifest.xml.
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>
you can find ADMOB_APP_ID by on ADMOB dashboard, click on the application
and check "App Settings". You can see the APP_ID which starts
typically with ca-app-pub-0123456789012345.
The second problem is, where you have declared AdView in your layout.
Remember you have to provide Ad unit not your publisherID, which
you can create in ADMOB dashboard by clicking on Ad Unit tab
under your application. Put the correct "ad unit" against your
AdView as below.
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" <!-- remember this is adUnit not App ID and this value above is for test banner Ad. -->
Once you have fixed above problems, do the following:-
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); in onCreate of your first Activity. This needs to be done only once and thus the right place is either your first activity or at application's onCreate callback.
Find the AdView in the activity onCreate where you have included AdView in the layout.
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Test Ads work by providing test adunit published by google.
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
Additionally, if you want to handle Ad events, do as follows:-
mAdView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
#Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.
}
});
Some of these possible solutions may sound obvious, but make sure you have these completed:
-replace "My Publisher ID" in android:value="My Publisher ID" with your actual publisher ID.
-make sure to include the internet permission in your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
If you have completed those, you can also try placing the following code in the "On create" section instead of your current:
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adRequest.setTesting(true);
adView.loadAd(adRequest);
adView.loadAd(new AdRequest());
or
AdManager.setTestDevices( new String[] {AdManager.TEST_EMULATOR});
AdView adView = (AdView)findViewById(R.id.adView);
adView.requestFreshAd();
Before publishing, don't forget be sure to get rid of the setTestDevice though!
make sure, your admob publisher ID is correct. It had happend with me once and I could not figure out the error for about 15 days.
In Admob every app that you submit gets a different publisher ID. It is unique per Application and not per User.
It might be an issue with the space, you need to ensure that the space is available for the ad to be displayed. If you have a padding on the parent layout it might reduce the space available. According to the google Admob docs no ad will be displayed if the space isn't there for it to be displayed.
"The SDK will request whatever size the requesting AdView was instantiated with. If there isn't enough space on the device's screen to display the ad, nothing will be shown."
So my suggestion is to ensure no padding is on the parent layout and actually assign a height and width to the banner ad like this
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_alignParentBottom="true"
android:layout_width="#dimen/banner_width"
android:layout_height="#dimen/banner_height"
ads:adSize="BANNER"
ads:adUnitId="My Publisher ID"
ads:loadAdOnCreate="true"/>
And store the appropriate dimensions in your dimens.xml in the values folder.
This is because admin inventory requires some requests to be generated to check that the app can make some profit!
Please let setup the ads properly and publish the app, after about 1k requests are made, the ads will automatically show up!
I too was suffering from this problem and got my answer when I published my own app!
If admob "App Id" and "Unit Id" is correct then upload on google play store it will show the add.
I was facing same type of issue but after upload on google play it resolve automatic.
My ads were shown by just having few request here are the following steps I made
Get More Requests You are saying that 400 imp but no ads just make another ad unit in same app it will start showing I also did this this method and ad started In my previous ad unit it have many request but no imp then I made another unit it started showing ads
Have patient in my account it take 4 days to show ads and my account was approved by Google in 1 hr it take a lot of time to build inventory in the server so be patient you will have your ads
Complaint Google at admob complatint they will check your app and chances of app is approved is 50-50%

Categories

Resources