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.
Add your AdMob app ID (identified in the AdMob UI) to your app's AndroidManifest.xml file. To do so, add a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID" . You can find your app ID in the AdMob UI.
Add you Admob App Id in the AndroidManifest.xml file between the “<application> </application>” tag like below. Add the following code to MainActivity to initialize Mobile Ads SDK (this only needs to be done once in the app lifecycle). You can find the App ID in the AdMob console.
Add the highlighted code to activity_main.xml to show the banner ad. Add the highlighted code to Main Activity to show Banner Ad. Add the Admob App Id and Banner Ad Id to string.xml .
You can find your app ID in the AdMob UI. For android:value, insert your own AdMob app ID, surrounded by quotation marks. <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 --> Key Point: In a real app, it is important that you use your actual AdMob app ID, not the one listed above.
Sign in to or sign up for an AdMob account. Register your app with AdMob. This step creates an AdMob app with a unique AdMob App ID that you'll need later in this guide. In your project-level build.gradle file, include Google's Maven repository and Maven central repository in both your buildscript and allprojects sections:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With