App stop working when trying to load AdMob ads - android

I have quiz app, and I want to make another quiz app that will be about something else.
I created new project in Android Studio and I copied all code from first quiz app.
Everything works fine, only when I start activity that have AdMob ads, app stops working.
In first quiz app everything works fine, ads are shown normally, but new quiz app stops working when trying to load AdMob ads.
Do you know where could be a problem?
This is what I use in xml file for AdMob ads:
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="id"
ads:adSize="SMART_BANNER"
ads:loadAdOnCreate="true"/>

Check the admob documentation and make sure you have the correct app ID set up in the admob details within your Android.manifest
You may have the ID from the previous app in there which will not work as the package name will be different.
https://developers.google.com/mobile-ads-sdk/

You can try
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="#drawable/back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="go"
android:orientation="vertical"
tools:context=".MainActivity" >
<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="ca-app-pub-7897489627187383/885626" />
</RelativeLayout>

Related

How to test ads if AdView failed to load 3

I use AdViews in my app in almost every activity.
The xml im using is:
<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_centerInParent="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/Banner_Ads"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintTop_toTopOf="parent"
app:gnt_template_type="#layout/gnt_small_template_view" />
I did every thing I could to test it by either using Test ID for the ads or by setting TestDeviceID and everything works good.
How can I be sure that it will work with real ads? when i did a single check of my app before distribution it gives me ad failed to load : 3.
Yes, I read that it can happen if I created ad unit recently and that it might might take time or that it means that my code is correct but there are no ads. But what does it means no ads? isnt AdView meant to be for ads?
Thank you

Firebase AdMob not working

I am a new Android Studio developer. I have made 2 apps with AdMob before, but now I made new app with ads, but they not going through. I have also tried with blank app, but the problem persists.
Here is the code below:
First this in MainActivity, the color is red and cannot resolve appear.
When I generate app, this occurred:
I have checked my code 5 times.
Please help me to resolve this.
This is in activity_main:
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

Admob not affected by activities?

i have created a game(surfaceview) and i am trying to implement admob wherein it must be fixed at the bottom.. i have successfully implemented the admob and shows it properly but what i did is i call it in main activity.
AdView adView = (AdView)findViewById(R.id.adView);
adView.loadAd(new AdRequest());
and i have this on all layouts
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/unit_id"
ads:loadAdOnCreate="true"
/>
what i need to do is show the admob but it will not be affected even if the screen switches it is fixed in the bottom part of the screen. i have searched for some thing like this but i have no success. i hope someone can help or even explain on how i can achieve this.
P.S. its like 1 banner for all activities.
I think it will be difficult (or impossible) to have just a single unique banner span multiple Activities. The ActivityGroup group class may have allowed this kind of thing, but it was never popular and anyway has been deprecated for a while.
Meantime there remains plenty of demand for the UX motif of switching between major views within the confines of one screen. But the mechanism has been reworked to use Fragments. If you can make your SurfaceView stuff work within a Fragment, then that might be your best bet. A layout might look something like this:
<LinearLayout>
<Fragment>
<AdView>
<LinearLayout>
When I did this kind of thing recently, I just put the AdMob code at the bottom of every Activity, and let it reload a fresh ad with every push. There has been no scolding from the Google side regarding too-frequent ad requests, and I am getting plenty of clicks.
Good luck!
Use Only Xml Coding without Java Code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="App ID"`enter code here`
ads:testDevices="25"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Can you wrap the whole screen in a relative layout? You can then align the banner to the parent's bottom. You other items should be declared with layout_above to keep them above the banner. The easiest way is to wrap them in another layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView" >
... your other items can go here
</RelativeLayout>
<com.google.ads.AdView
android:id="#id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="App ID"`enter code here`
ads:testDevices="25"
ads:loadAdOnCreate="true" />
</RelativeLayout>

Android Rounded Line in Ad / Ad gaining focus

I've implemented Google Ad's in my app. The problem is: every time I touch the ad and go back to the application, a rounded line appears. It's like the ad gains focus.
A picture of the problem.
The ad code (that I'm merging in the app) is as follows:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<com.google.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
ads:adUnitId="a150203b883dd6d"
ads:adSize="BANNER"
android:focusable="false"
android:focusableInTouchMode="false"
ads:testDevices="TEST_EMULATOR, 39e0b3669eb01337"
ads:loadAdOnCreate="true"/>
</merge>
Any thoughts?
could it be that the ad is rendered html in a webview? if so, and you have access to the css being presented there edit it like so:
a {outline:0}
a:focus { outline:0;}

Admob ads not showing up

I've got a problem with Admob not showing up Ads...
Here's the LogCat:
WARN/AdMobSDK(502): Ignoring requestFreshAd() because we are requesting an ad right now already.
INFO/AdMobSDK(502): No fill. Server replied that no ads are available (1164ms)
INFO/AdMobSDK(502): No fill. Server replied that no ads are available (846ms)
I've tried test mode, no test mode, emulator, real phone, etc. It never shows anything up, but I get requests and prints on Admob stats, like if it ever worked...
AFAIK, I did everything in the Admob Android SDK... the only thing that could be the cause of any problems, IMHO, would be the fact that I'm using tabbed layout with scrollview and then a relativelayout where the ad shows...
Here's a sample of the layout for a tab:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.xxx.xxx"
android:id="#+id/tababout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000"
android:padding="10px">
<ImageView
android:id="#+id/label_img"
android:src="#drawable/about_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside" />
<TextView android:id="#+id/label_know_more_desc"
style="#style/Desc"
android:layout_below="#id/label_img"
android:text="#string/tab_about_know_more_desc" />
<Button android:id="#+id/bt_know_more"
style="#style/Button"
android:gravity="center_vertical|center_horizontal"
android:layout_below="#id/label_know_more_desc"
android:text="#string/tab_about_know_more_bt" />
<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" />
</RelativeLayout>
</ScrollView>
And here's the main.xml, not that I think you need it:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000"
android:paddingTop="5px">
</FrameLayout>
</LinearLayout>
</TabHost>
I've read in Admob ads will not display when placed inside a tabview that the problem could be the 10px padding I'm throwing in, but even if I disable that, it doesn't work.
I even tried moving the xmlns:myapp to RelativeLayout, but obviously didn't change anything....
Also, I've made my first live ad request over 24 hours ago...
EDIT
Ok, now I'm getting somewhere, I've managed to get test ads showing up (my setTestDevices was too late in the onCreate code, I pushed it up to the first lines), but not real ones... am I missing something? I obviously commented out the setTestDevices line and no ads show up
EDIT 2
Well, I added two internal ads (I already had internal ads enabled, but no internal ads set), and suddenly ads started showing on my app (not only internal ads).
I guess everything altogether made it work?! :)
Thanks everyone!
You aren't positioning the ad's in the RelativeLayout (they need a layout_above or layout_below or whatever to specify where to put them).
Also there is a minimum size for admob that you might want to ensure you match, I think it's like 48dip in height at least, not sure what the horizontal is.
Lastly I don't know where you are trying to place your ad's, but it probably would make more sense in your main frame-layout, I have a padding at the bottom of my app which I use for the ad-view.
Edit: also if your app is public check for ad-revenue. Android pre 2.3 allowed ad's to be hidden behind views and still register clicks. I actually made my initial $1 before my ad's were even visible by anyone.
Another reason that the AdMob Ads won't show up is that you haven't declared the AdActivity which will display the ads when they are clicked on. Without the AdActivity declared in my AndroidManifest.xml, I don't see the ads. With it declared, the Ads show up.
...AndroidManifest.xml...
<!-- AdMob -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>

Categories

Resources