Check if ads:testdevice is working properly? - android

I put this in my LinearLayout
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="d7fd8f9ghf042k4"
ads:loadAdOnCreate="true"
ads:testDevices="34HF70000000G501" />
I'm still testing my application, but when I checked my AdMob account, I found out this:
I don't understand, what's happening? Am I getting revenue for clicking my own Ads?
If Yes, how could this happen when I have mentioned this line ads:testDevices="34HF70000000G501" in my XML layout?

The ID you put inside of ads:testDevices needs to be the hashed device ID which is output in LogCat when you load an ad request on the device. It does not work if you use your actual device id.

Related

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);

adView.loadAd() is crashing my entire program

Im trying to integrate admob ads into my app and I've been trying to follow the tutorials on Google's APIs and their code is causing my entire app to crash.
I want to think it's because I'm testing on my phone and I havent included adRequest.addTestDevice("TEST_DEVICE_ID"); because to obtain your device id you first need to request an ad, and I am failing exactly where I am requesting an ad.
This is what I have in my main.java taken line for line from androids api tutorials. Log cat says it's crashing at adView.loadAd(adRequest);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Here's the XML
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="adUnitId"
/>
and finally here is what log cat has to say: http://imgur.com/UfB45YF
referenced api: https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play
Do you think it's crashing because I don't have my test device ID included? Or is there something else happening?
If it crashing on adView.loadAd with a NullPointerException then you have no View called R.id.adView in that Activity's layout.
Look at your Activity's onCreate and what layout you have specified in setContentView. and make sure that you aren't also using something like libGDX AndroidApplication which sets it own ContentView.
Finally do a clean build.
If you are putting the code in MainActivity.java and you have multiple layouts associated ie:
activity_main.xml
sw600dp\activity_main.xml
sw720dp\activity_main.xml
then you need to put the com.google.android.gms.ads.AdView xml code in each layout regardless of what device you are testing for.
That was my problem. Hope this helps others.
Also be sure the set your dependencies and change your manifest.
I had the same problem. When I was debugging I saw an error about the google play services version number being incorrect, and it showed the real value. I added this value to the strings.xml file:
<integer name="google_play_services_version">7095000</integer>
Once it was in, everything ran fine.

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.

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%

How to implement Admob AdView in Android app

I want to use Admob in my app. I've downloaded the SDK and followed the steps. Sometimes, I get an ad in return, but most of the time, I get an entry in LogCat that says "Server did not find any ads" or something to that effect. Test mode is enabled, says the Admob site. I think I might be doing something wrong. Where can I get a step-by-step guide to insert admob ads in Android apps? The Admob developer site is rather lacking.
Also, let's assume that everything's gone well and that I'd now like to deploy the app. How do I turn off test mode for Admob ads?
Thank you.
Download the AdMob jar file http://www.admob.com/my_sites/
Create a package on your project and call it "libs" and paste this file AdMob.jar there
Right click on your project a select the library, add there the path for the ADMOB.jar you just saved.
If you're creating your AdView on your XML, you can add this line.
This is an example for testing. When you get your own ID from ADMob, place it on the adUnitID and erase the test line.
com.google.ads.AdView
android:id="#+id/adView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="a14f59e5c442767"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"
</com.google.ads.AdView>
Now go to your .java that it calling this layout and create your AdView
AdView adView = (AdView)this.findViewById(R.id.adView1);
adView.loadAd(new AdRequest());
This is how I do and its been working good so far.
Sorry about bad english, to much code and no sleep!
just follow the instructions on this site:
http://developer.admob.com/wiki/Android#AdMob_Android_SDK
I guess you did not activate the test mode for your device or the emulator?!
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
It seems as though this might have changed to
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("E83D20734F72FB3108F104ABC0FFC738"); // My T-Mobile G1 test phone
see http://code.google.com/mobile/ads/docs/android/intermediate.html
As per Tom's comment below the value to provide for addTestDevice is actually the MD5 hash of the device ID. YOu can get this from the logcat.
Just add a permission to the Android mainfest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Check it once.
Then add this code:
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
You don't need to call it programmatically.
It took me a while until I get what device is AdMob's sdk what expecting cuz' I was thinking it was something related to the real device like ( adb devices )
But here is a comment from the official documentation that cleared it up.
There will be a log message with the code needed to add the current
device to the list of test devices
You may get an message similar to it
I/Ads(26674): To get test ads on this device, call adRequest.addTestDevice("F1254CDFBA84BDC27F5C7C6E12445D06");
All you have to do after that is to place this ID into your layout xml as below
<com.google.ads.AdView
android:layout_alignParentBottom="true"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/publisherId"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, F1254CDFBA84BDC27F5C7C6E12445D06" />
Hope it helps you guys out
Paulo Miguel Almeida

Categories

Resources