getting started with admob for android - confused about documentation - android

I just started looking into putting Admob ads into the android app I'm building. So far, no good. I've been following the example in the AdMod_Android_SDK_Instructions.pdf that I downloaded from the adMob website, but am confused. On page 7 I see the import statements refer to the package as com.admob.android.ads - but in the SDK I downloaded, the package is com.google.ads - is this a leftover from before google acquired admob? It then goes on to call the method adView.requestFreshAd(); - which does not exist in the latest code.
Please can someone help me out with some code that actually works? My specific errors from logcat are:
AdView missing required XML attribute adUnitId.
... then after I call adView.loadAd(new AdRequest()); i get:
Invalid unknown request error: Cannot determine request type. Is your ad unit Id correct?
onFailedToReceiveAd(Invalid Google Ad request).
Any help, much appreciated!
Thanks.

As of 4.1.0,
mob1lejunkie is perfectly right, you can remove
attrs.xml
background, primarytextcolor, secondarytextcolor attributes (and define them from admob web site on the manage setting tab of your app)
remove the name space xmlns:myapp from your main layout in your xml file and replace it by xmlns:ads (take care here !! The new xmlns is not in /apk/res but apk/lib )
change the namespace of adUnitID and adSize in the adView xml snippet
so here is a working xml snippet with admob 4.1.0 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="fill_parent"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<com.google.ads.AdView android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14d7f7d2180609"
ads:adSize="BANNER" />
</RelativeLayout>
Isn't it a bit light from google to ask devs to put in place a new code and use a librairy that is not yet documented by google themselves ? It reminds me of the adwhirl adventure...
Nevertheless, I must say I am glad google put that in place and remove the attrs.xml stuff. It is much easier to use admob with project inheritance in android.
Also, with respect to using multiple adviews in a project, please note that with this release, it is now possible to add you admob id in the strings.xml file of your application as requested on this thread : http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/c57917b4491a0c1
Just put it this way in your xml layouts for all your adviews :
ads:adUnitId="#string/admob_unit_id"
and then
<string name="admob_unit_id">a14d7f7d2180609</string>
in your strings.xml file and all other localized versions of this file.
This will give you a single centralized location to enter your admob id in all your views.
Great release indeed.
Regards,
Steff

I had the similar issue with 4.1.0 and it turns out Admob documentation (as of 15th May) is out of date.
attrs.xml is no longer needed and the namespace in the layout needs to be
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads
rater then the old
xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename

Seems like the PDF is outdated.
Try reading Google AdMob Ads Android Fundamentals

This page helped me with with placing an ad in the XML layout: http://code.google.com/mobile/ads/docs/android/banner_xml.html

Related

Ads do not show in my application

I don't know what I am missing, currently I have:
build gradle(project): maven {
url "https://maven.google.com"
}
build gradle(app):implementation 'com.google.android.gms:play-services-ads:15.0.1'
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
in the xml:
<com.google.android.gms.ads.AdView
android:id="#+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintEnd_toEndOf="#+id/normBtnID"
app:layout_constraintStart_toStartOf="#+id/ratingBtnID"
app:layout_constraintTop_toBottomOf="#+id/ratingBtnID" />
I have tried several codes, tried to put the adview programmatically and in the xml, for the current code I got the error adSize missing but it's there, when I add the ad programmatically it just shows a blank screen when launches the app
You need to add the following to either the activity or the Application class...
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
Read more here:
https://developers.google.com/admob/android/quick-start
I thin you must to use firebase firstly you can follow this link to do that and adding ads
in correct way
https://firebase.google.com/docs/admob/android/quick-start
if you did that before
I think the error is from your admob account
go to Payments and confirm info there
ads will appear simply
I hope that will be help you
Could you try android:layout_width="match_parent" and android:layout_height="70dp" on Adview?
I faced same problem yesterday, hardcoded layout_height is work on my case.

Android Ads are not clickable

I am trying to add my first advertisement to my android app. I followed a tutorial, and added the following code to my xml file
<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="#string/banner_ad_unit_id"
>
</com.google.android.gms.ads.AdView>
It displays the ad in my emulator as well as in my real device . In my emulator, the ads like 'Install This App' are displaying and download symbol also visible. In my emulator , the ad is visible and refreshing clearly but click is not at all enabled. No response with a click.
I googled stack overflow questions but no apt answers were there. Any help will be appreciated.
ps: I didnt try clicking in my emulator due to the admob ban issues
Check Your Layout Arrangements. May be Some other Layouts overlaps the ad container.So when you click it clicks the overlapped layout components.
Make sure the ad is active/ enabled in your admob account. As I remember it shows colour green when active.
Try creating another ad unit and add the ad again.
#arunprakashpj, Your AdView seems ok, but you need to check the parent layout to see if everything is ok.
You need to be sure this isn`t problem of the Ad itself. To prevent the admob ban issues you can set the emulator (or any device) as a Test Device, so you'll get Test banners that you may click without fear.
To see how to implement test banners, check this link (they have an example there): https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#enjoy_a_freshly_loaded_ad
Please, let us know the click result when you're using the test banners. (If click works in test ads, it means that the problem probably will be the Ad itself and not your code).
The way I solved such problem:
In Unity3D 4.XX in your current Assets folder open
Plugins > Android > AndroidManifest.xml
In the AndroidManifest.xml file under the
application > activity
you can find unityplayer.ForwardNativeEventsToDalvik property, which by default is false, like this:
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
so change it to true,
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
afterthat Save it and re-build.
In my case I was missing adding the ad-mob dependencies to the gradile, once done it worked fine.

ActionBarSherlock + Google Maps API, Failed to find style 'mapViewStyle' in current theme

First of all, I know there are thousens of post asking the same, but after few days looking for a valid answer and try everything I'm still having the same problem...
So let's expose my situation:
I'm using ABS + google maps, so my map view xml is the following:
<?xml version="1.0" encoding="utf-8"?>
<com.actionbarsherlock.internal.view.menu.ActionMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0PGmnrCR70lothfjc_sFGTdFtESQPOksYKQWYpw"
android:clickable="true" />
</com.actionbarsherlock.internal.view.menu.ActionMenuItemView>
Few days ago everything was good, I was able to do my stuff in the app and everything. But suddenly I just made a little change, insert a framelayout to display more options in the screen. I tried to go back but was impossible...
I'm really deseparated, what can I do? maybe I can create a new project and paste all my code, but not really sure if it's going to work...
Any suggestions?
BTW my error code is this one
Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style 'mapViewStyle' in current theme
java.lang.NullPointerException
Exception details are logged in Window > Show View > Error Log
Thank you for your time!
I finally solve the problem, the error in the screen is still there, but just like a warining and when I execute the app same to work fine.
The only think I made, is change the specific layout of ABS and put a frame layout.

Why won't my Admob Ads show up in my android application?

I have made an application for the Android Market and I tried to include an Ad in it using Admob. I have everything set up correctly, but the ad doesn't show up no matter what I do. If I check the Admob Marketplace I can see that there were a lot of requests sent and I got a good fillrate, too, but my ads simply do not show up in my program, as if they were invisible.
The AdView appears if I am in the graphical XML designer, but just won't show up when I run the program, although as I said, it sends a request. I would really appreciate it if you could help me out! :)
By the way, here is the main code of the AdView(I tried to add it using Java too, but it didn't show up either):
<com.google.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ad"
ads:loadAdOnCreate="true"
ads:adSize="BANNER"
ads:adUnitId="MyIdHere">
</com.google.ads.AdView>
I found out that the padding of my layout prevented the Adview from
appearing. Removing the padding fixes the problem!
-- answer by Calin

adding admob widget

i cant seem to figure out how to add the admob widget into my application. i want to add the widget to a linearlayout that is the child of a relative layout. the linerlayout was created just for the ad.
and have it update/refresh the ad each time a button is pressed. i have already imported the JAR,edited my manifest to include the permissions and publisher id. but i cant seem to exactly figure out how to add integrate the admob code.
/facepalm. im an idiot problem solved.
There is a PDF you can download from Admob, on the same page that you downloaded the JAR file. I'd give you the link, but I think you have to be logged in to the website to get to it. You need to follow that PDF step by step. For example I don't see that you mention anything about the attrs.xml file that you need to put in your /res/values directory, or adding something like this inside your LinearLayout:
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
/>
Have you done all the steps in that PDF file? If so, then can you be more specific about the problem you are having.

Categories

Resources