I add admob for my app as guide:
https://firebase.google.com/docs/admob/android/quick-start
and
https://www.youtube.com/watch?v=OLLLRUPICcc&list=PLOU2XLYxmsIKX0pUJV3uqp6N3NeHwHh0c&index=1&spfreload=5
But admob is only view:
Nice job! You're displaying a 320x50 test ad from admob
It does NOT change other ads. Please help me.
Code as below:
In activity at onCreate:
MobileAds.initialize(this, "ca-app-pub-9518053516260440/6844465750");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
in xml:
<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="50dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
Acording to the Quickstart
If you haven't created an AdMob account and registered an app yet,
there's no better time than now. If you're just experimenting with the
SDK in a Hello World app, though, you can use this App ID to call the
initialize method: ca-app-pub-3940256099942544~3347511713.
You are using testing appID. To make it work you need to create your own account. Than create application and use your own application ID. This will let you customize what ads should show and it will show actual ads. But for testing you should use this AppID, because you should not click on your own ads.
Fix your appID in xml. But even then it takes some time to actualy start working. It might take about day to start showing real ads.
I am beginner in using adMob so I want to know what steps should be taken so that I will not violate the adMob policies in future.
Please find my code below which I have followed:
XML file which have adView :
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-XXXXXXXXXXXX/XXXXXXXXXXXXXXXXXX">
</com.google.android.gms.ads.AdView>
onCreate of Activity which load's the ad.
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.banner_ad_layout);
AdView adView=(AdView) findViewById(R.id.adView);
AdRequest adRequest=new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
so now I want to know how can I enable live ad's when I upload my apk for production and how can I enable dummy ad's or test ad's during testing and development stage.
Please let me know the code changes I have to make during development and production.
Initially I used to click live ad's even during the development phase so my adMob account is blocked and not able to get any live ad's from adMob server so after some investigation I get to know how can i display some dummy ad's for testing and development stage.
Here is the answer for it:
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
"69AEF8955FAE39BFDF64CDB6D8911089").build();
use the above line of code during testing and development phase.Replace 69..... with the string that u find in your logcat when u run your application.
AdRequest adRequest=new AdRequest.Builder().build();
use the above code during production phase,comment this during testing and development phase.
So I have a project (module really since I'm using IntelliJ, but I'll use Eclipse terms) with Activity (Let's call it X) which loads an AdView and it all works just fine. Now I have another Activity (let's call it Y) which opens after certain actions, that Activity is inside a library project. Activity Y opens just fine and works well but the AdView I add to it never has anything in it, it is just just blank. Here are some odd messages I see on the logs:
I/Ads﹕ Starting ad request.
I/webclipboard﹕ clipservice: android.sec.clipboard.ClipboardExManager#4293f940
W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
I/Adreno200-EGLSUB﹕ <ConfigWindowMatch:2087>: Format RGBA_8888.
onSizeChanged - w:640 h:100
W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
These two messages happen later, after a bit of time (close to the 60 seconds):
W/Ads﹕ Timed out waiting for WebView to finish loading.
I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
W/Ads﹕ Failed to load ad: 2
And here is the code I use to create the AdView:
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(id);
buttonsAndSeekbarLayout.addView(adView);
final AdRequest.Builder builder = new AdRequest.Builder();
AdRequest adRequest = builder.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
I should also mention that I am using other parts of the Google Play Services on that library project so I think it is configured correctly.
Thanks.
EDIT: I should mention that even if I add the adView on the xml it is still just blank!
EDIT2: Added some extra messages above. Also I noticed this message which after doing a search seems to be AdView related:
D/WebKit﹕ SQLite database failed to load from /FileSyetmQuota.db
EDIT3: I found something odd. I added in app purchase to that screen, when the purchase is done, right before I remove the ad (because of the purchase), it shows up for a split of a second.
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.. Ignore that message, it appears even when you've running your GP services correctly, that's not the issue.
The code part where you create your AdView and load an ad is perfect, that's neither the issue (I'm running exactly the same code on several projects and it works).
Having in account the above, my bets are just two:
Somehow, the library project is interfering with the loading of the ad. Ad loading has a timeout, if you're doing some hard work, probably there's no time enough to load the ad and it times-out, so probably that's why you're seeing the Timed out waiting for WebView to finish loading. message. In this case, try putting the ad loading within a Thread (or an AsyncTask).
A layout rendering issue. You have to check whether the Ad has enough space to show up, i.e., 640 in width x 100 in height minimally. If you don't have that space, the ad won't show up.
---- EDIT ----
To run the code within a Thread, use this code:
new Thread(
new Runnable() {
#Override
public void run() {
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(id);
// This will ensure it is run within the main UI.
runOnUiThread(new Runnable() {
public void run() {
buttonsAndSeekbarLayout.addView(adView);
}
});
final AdRequest.Builder builder = new AdRequest.Builder();
AdRequest adRequest = builder.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
}
}).start();
hey please try to load ads like bellow example
first update your Google play lib to 4.3
The easiest way to incorporate an ad is to simply define your AdView as you would any other part of your res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
</LinearLayout>
you must replace MY_AD_UNIT_ID with your AdMob ad unit ID.
To fetch ads, look up the AdView as a resource via findViewById, create an AdRequest, and invoke loadAd:
import com.google.android.gms.ads.*;
public class BannerExample extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 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);
}
}
Figured it out, in my code I call webViewInstance.pauseTimers() and apparently that applies to all web views.
I am trying to set the AdMob banner ABOVE the Tabs in a TabsActivity:
public class FundsReportTabsActivity extends TabsActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AdView adView = new AdView(activity, AdSize.BANNER, AD_UNIT_ID);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout"
// Add the adView to it
getTabHost().addView(adView, 0, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("E0154BC3F11C778234254195FA1164F");
adRequest.setTesting(true);
// Initiate a generic request to load it with an ad
adView.loadAd(adRequest);
}
However, the banner does not appear, even though I have this logcat:
09-29 22:23:09.755: INFO/Ads(16158): onReceiveAd()
and don't see any related warning/error.
Does anyone have an idea? Thanks!
Check your logcat for a warning or verbose saying no ads in inventory. Some times when you first sign up or are using admob it takes some time before the ads start appearing. Also make sure you have provided a linear layout for the ad. And if you watch the logcat file during the activity with the ad you will see a content containing items that pertain to the ad. I know i had trouble with admob at first. The same issue you are having. It just took some time.
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%