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
Related
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.
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"
This is strange, yet I see it all the time as I have lots of reasons to display just a simple question mark in this app.
When editing with the Eclipse graphical layout editor, everything is fine...until I tell a TextEdit or a Button to display just a question mark. Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/test_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/question_mark" />
</LinearLayout>
And the string is defined in res/values/strings.xml. The relevant line is:
<string name="question_mark">\u003f</string>
The error message I get is:
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.
Couldn't find theme resource for the current theme
Change the text, and the error message goes away.
You can see that in my struggles, I'm even trying to use the unicode version of a question mark. And yes, \? doesn't work either.
Note that this only happens when the graphical layout editor is set to API 7 or greater.
Now the graphical layout editor displays the question mark properly, and the emulator and my phone display the question mark without any problems. I'm just annoyed with the error message taking up 1/4 of my screen for all my layouts (and obscuring other error messages that may crop up).
Any suggestions?
First, test this again on the ADT 21 release that shipped today.
If the problem continues, create a sample project that demonstrates the issue, and post it along with step-by-step instructions on the Android issue tracker.
Well, this is a really crappy hack, but it kind of works--if you stand on your head!
You can use the unicode \u00bf as in
<TextView
android:id="#+id/test_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\u00bf" />
It's not a normal question mark, but it's close enough for a hack and gets that annoying error message out of your hair. And it might even increase the humor quotient of your app!
But PLEASE, if anyone out there has a real fix, post it!
Wow, I entered a bug report...[time marches on]...finally, I get a few emails as the Google team starts to look at it.
Today, I received some good news. It looks like the bug has been fixed (and they found a few related bugs, which have been fixed as well). The fix will be in the next release, Version 21.1 Preview 2. You can read the official details here.
Looking forward to it!
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 have an Activity in a tablet app and I want to show different Fragments depending on the orientation. I figured the easiest way to do this was just to define two different layout XML files, one for landscape and one for portrait. In other words I have /layout/home.xml which looks like this:
<LinearLayout android:orientation="horizontal">
<fragment class="com.foo.app.Frag1" android:id="frag1"/>
<fragment class="com.foo.app.Frag2" android:id="frag2"/>
</LinearLayout>
And then in /layout-port/home.xml:
<LinearLayout android:orientation="vertical">
<fragment class="com.foo.app.Frag2" android:id="frag2"/>
<fragment class="com.foo.app.Frag3" android:id="frag3"/>
</LinearLayout>
When I run it, I can start in landscape and go to portrait, and everything is fine. However, when I go from portrait to landscape, the app crashes with a android.content.res.Resources$NotFoundException with Resource ID equal to "frag3." That's right it's looking for Frag3 when going to landscape made, and there is no Frag3 in that mode. This happens during the Activity.onCreate stack, so before any of my code has any chance to make the app crash.
Are Fragments not supposed to work this way? Do I need to use a FragmentTransaction instead?
It's hard to say without seeing the code- However, Resources.NotFoundException usually means you tried to look up an asset (think R.layout.xx, R.drawable.xx, etc) incorrectly.
That said, I tried writing a small app using your layout XML, and the compiler yelled at me for hardcoding strings as the ID's when I copied in your XML code to test it out. Try switching the values of the android:id attribute to read like this:
android:id="android:id="#+id/frag1"
that might fix the issue.