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.
Related
I'm using the latest android admob SDK 6.3.1 and the first ad is downloaded and is shown on the device. Then after the refresh rate time is due, in my case 30 seconds, logcat shows that the ad has been downloaded and the new add is shown correctly. However after a second or less the new ad disappears leaving the space where the add should be blank.
Through trial and error I have found that if I touch the blank space where the ad should be it opens the correct 2nd ad link in the browser. So the add appears to be hidden in some way.
Also if I touch the bottom left hand corner of the blank 2nd ad, then the 2nd ad is shown correctly.
I've tried this with both relative and linear layouts and on different devices but the same thing happens. The first Ad shows correctly, after the refresh interval, the 2nd and all subsequent ads are downloaded and briefly displayed before going blank.
As well as trying different layouts I have also tried setting adview code in XML and programmatically in java source.
That fact that I briefly see the 2nd ad confirms that everything is okay admob server side so that makes me think it's the layout. But I have tried every combination can think of without success.
Ive tried setting: android:layout_width="320dp" android:layout_height="50dp" instead of "wrap_content" or "fill_parent".
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</LinearLayout>
This is what I have now which is as per the official admob page.
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
This is my third day trying to solve this, has anyone got any clues?
Do you think it could be device specific. Or API specific.
Best Answer for This Question is that :-
You can set up an Animation to slide the banner down, and when it's out of the view (setup a onAnimationComplete listener) call it's method :
Code in Activity:-
For visible:-
setVisibility(View.VISIBLE);
For:not Hide
setVisibility(View.INVISIBLE);
so it will not take up space in layout any more.
I'm pretty sure this can happen if the same adview id name is used in more than one activity xml.
android:id="#+id/adMob1"
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
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
Ok, I'm officially at my wit's end here. Working on an Android app that uses AdMob. Everything is set up to the letter following their instructions, no errors, etc.
Problem is: I only see ads when the phone is in landscape orientation.
I've searched online and done every last thing I can think of to test this:
Tried it in test mode and normal mode
Removed the orientation configChanges from my main activity's manifest and their handlers in the code, in case they were causing it
Removed all functionality of the app so that onCreate looked like the one in the instructions above
Tried every possible change of main layout - placing it in different locations, removing other widgets, different layouts, etc
These are just a summary of a few hours of testing, every time the result is the same. Portrait shows no ad, landscape shows the ad (as/where expected - not stretched, but the max width issue is well known and not a problem).
Logcat shows everything to be working properly in both orientations: Requests are made, ads are returned. I can click on the ads that appear in landscape, but tapping the area they're meant to be in portrait does nothing.
It's driving me mental! Any ideas?
Edit: Okay, the problem is gone but I'm afraid I can't really call it a "fix". I remembered ads working fine in a previous but similar app. It was using a different version of the AdMob SDK - I don't know any details, but admob-sdk-android.jar is 77kb rather than 136kb.
I copied the 77kb one from the old app into the new app, along with the attrs.xml file, which necessitated changing the primaryTextColor attribute in the AdView to textColor, and that's it. Works perfectly now - and as a bonus, the ads stretch horizontally across the whole screen in landscape view as well!
I'm posting this as an edit rather than an answer since it seems more appropriate and I'd still love to know if anyone can shed some light on the issue. Was it an AdMob SDK issue?
I also encountered this issue, you should check if the parent container is padded, if it is, remove padding and all of sudden ads will appear. I don't find it very logical but it helps.
Not sure if this will help, but i had a similar issue, where in a landscape game, the ads would appear in portrait mode only. On a tab 2 i borrowed for testing from someone. Turned out there was some sort of screen lock on the device which caused it. Spent hours trying to chase the bug down.
Check this layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".AddTest"
tools:ignore="MergeRootFrame" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
>
</com.google.android.gms.ads.AdView>
</RelativeLayout>
I have same problem in tools:ignore = "aaaaaaaaa" and padding
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.