I'm trying to place AdView to layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/home_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"/>
</LinearLayout>
It is showing correct my content and the boxholder in the bottom of view, there is supposed to be an adView, but i see empty box and ads doesnt appear.
In my logs, i see:
Ad finished loading.
W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 30285
Scheduling ad refresh 30000 milliseconds from now.
Ad finished loading.
Ad is not visible. Not refreshing ad.
What I'm doing wrong? Thank you in advance.
Following are possible errors
Your Banner ad unit id is not correct
You have not set ad properly on Google ad mob follow below link
follow this link
If my answer resolve your issue, please vote up
You have set the height of the inner LinearLayout to match_parent. THat will consume all of the available space leaving none for your AdView, so it will think it is not visible. CHange the LinearLayout to:
<LinearLayout
android:id="#+id/home_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
Got answer for my question. XML was correct, just Adblock havent initialized in workflow. To do that, I needed just initialize in activity adMob block in onCreate Action:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Also import depreacted libraries:
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
Thank others for help and suggestions.
Related
I am implementing banner ads, but getting the error "Required XML attribute "adsize" was missing". I was using the developer.google.com link to add admob
I also visited other stackoverflow questions like as Required XML attribute 'adsize' was missing (google play service)
and I have already implemented everything but the error remains the same. Here is the code.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.abhishek.canddatastructureprograms.MainActivity">
<FrameLayout
android:id="#+id/sample_content_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
MainActivity.java
added the following code in onCreate() method.
AdView mAdview= (AdView) findViewById(R.id.adView);
//AdRequest mAdRequest= new AdRequest().Builder.build();
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("9F099BD5E5700664591DEC5FDC92A40E") // An example device ID
.build();
mAdview.loadAd(request);
Please let me know if I need to add any more details or code.
Code seems to be right. Try to remove all left and right paddings or margins, maybe you get this error because you have too small screen to show add.
I'm facing a strange problem by adding adMob banner to my app.
It's first time i do this with android studio, so i've followed tutorial (the only different thing is the edit of build.gradle file).
I've add banner to layout as always:
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_cut"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/banner" />
<com.google.android.gms.ads.AdView
android:id="#+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/admob_id" />
</RelativeLayout>
and initialized banner into my activity:
AdView mAdView = (AdView) findViewById(R.id.banner);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Now when i launch my app, banner space is empty, and i obtain some warning like
W/Ads﹕ Not enough space to show ad. Needs 360x50 dp, but only has 328x479 dp.
but log told me that banner is loaded correctly:
I/Ads﹕ Scheduling ad refresh 40000 milliseconds from now.
I/Ads﹕ Ad finished loading.
How can i solve this problem?
You will see, successfully:
I/Ads﹕ Scheduling ad refresh 40000 milliseconds from now.
I/Ads﹕ Ad finished loading.
AdMob may or may not complain about "having enough room" but it will not show up if there is padding in the parent view. You need to wrap the views you want to have padding in either another layout or add padding to that particular view directly.
Please remove the padding from the parent layout:
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_cut"
tools:context=".MainActivity">
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/banner" />
<com.google.android.gms.ads.AdView
android:id="#+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/admob_id" />
</RelativeLayout>
In case you're still struggling I've found a working example on http://www.ahotbrew.com/android-studio-admob-banner-and-interstitial-tutorial/
Just click on download code.
today Google suspended my app saying that my ads violated Google TOS but I don't know what did it actually violate. I think there might be something wrong with my code structure i guess because I tried publishing it two times and in both it got suspended.
In my app I am using a View Pager and inside it I have 4 tabs. So the ads are placed in the View Pager as below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<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"
app:adSize="SMART_BANNER"
app:adUnitId="#string/banner_ad_unit_id" >
</com.google.android.gms.ads.AdView>
and the code in the View Pager activity
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
I would be very thankful if someone told me the reason behind the continuous suspension.
I have a PreferenceActivity for a LiveWallpaper and have used the solution here (LINK) to create an Admob ad. It works, but the ad disappers when the user scrolls up or down and loads again when it comes into view. Is there a way so that the ad always stays at the bottom (or top) of the activity (like in a regular activity)?
Before
((LinearLayout)view).addView(adView);
Try setting the layoutParam like
adView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT))
OR Change the layout like following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id"/>
</RelativeLayout>
And code part would be like this:
mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new ToastAdListener(this));
mAdView.loadAd(new AdRequest.Builder().build());
Android 2.3.3
I have followed the steps, found in the this tutorial. When I run the application in my device(mobile), the ads are getting displayed. No Problem here. But when I try to view the activity in my eclipse, I get a blank screen with the NullPointerException. I have taken the screenshot. Please refer to it.
Then, I have clicked on the link, given in the exception's "detail" (SourceFile:670) and I get the following details..
I have clicked on the Add Source, and browsed to the jar file in my application->libs folder. Then I get the following...
Here are my xml and java codes that I have used...
XML
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="#000000"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a151xxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<TextView
android:id="#+id/txtViewPrevious"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="right"
android:height="25dp"
android:singleLine="true"
android:text=""
android:textSize="16sp" />
.....
.....
Java
private AdView adView;
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
Libs
How do i get rid of these exceptions?
Thanks in Advance...
This happens. It's normal. Eclipse can't display custom views sometimes (most of the time actually).
Download the latest SDK. Per the release notes, this was fixed in v6.3.0.