In admob management AdUnit shows in format
ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn
How am i suppose to put it in xml layout?
Is this correct?
<com.google.android.gms.ads.AdView
android:id="#+id/ad1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn"
/>
You already have the correct Ad unitId..
It should be something like "ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn"
Related
I'm trying to implement AdMob into an Android App. The app has 1 activity(MainActivity) and in this activity I have 10 fragments. I would like to display a banner ad in each fragment. Can I use the same ad unit for all the fragments or it will be necessary to create an ad unit for each one?
You can use one Banner Ad Id for one Application. Just create string in string.xml and use the same in application. Like this -
strings.xml
<string name="ad_banner">ca-app-pub-903891699798xxxx/244573xxxx</string>
layout.xml
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="1dp"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_banner" />
What is the appropriate value for adSize in the xml file if I want to include an InterstitialAd and not a Banner?
My problem is that including an InterstitialAd from Admin to my application does not work properly.
So far I followed the official tutorial, but it says nothing about the value of ads:adSize in the xml. When I implemented a ad with a banner this attribute was set with "BANNER" but I suppose this is not the solution when I want to have an Interstitial ad.
So could you please tell me which other values than BANNER are possible for ads:adSize or what else I should use to make it work?
Thanks a lot
Below code required only when you want to add banner view at your App view.
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
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="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
Follow instruction of this link to implement InterstitialAd in your App.
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>
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;}
So, I currently have an AdView in my layout like this:
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="XXXXXXXXXXXXXX"
ads:adSize="BANNER"
ads:loadAdOnCreate="false"/>
and that works just fine. However, I have to get the AdView in the source code in order to pass it a request for the Emulator and my personal phone to be TestingDevices and not receive real ads. Is there a way I can list those in the XML directly? or even force the AdView to ONLY show test ads, so that I don't have to have that chunk of code and can set the AdView to loadAdOnCreate?
Thanks.
Sure, add this to the xml:
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
I found it here: https://developers.google.com/mobile-ads-sdk/docs/android/banner_xml