Android Admob ad not visible - android

I have added all required code but admob ad is not visible neither on emulator nor on my device. I have created Admob account today itself, is it the reason why i am not able to see add?
The ad part is completely blank while running the app.
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("MyDeviceId_1").addTestDevice("MyDeviceId") // An example device ID
.build();
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<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>

remove these lines from your root layout
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
if your AdView will not get full width of your screen, it will not be visible
Also you need to load ad in your AdView
adView.loadAd(request);
check this

For load & show the Admob banner add need to more space .Don't get more space to show on Admob banner add for declaration your root layout(RelativeLayout).Please remove those two line..
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
Must be you need to add this line on your java code.
adView.loadAd(request);
I don't able to show this line on your code.Are you add this line.Please check this.

Be sure to add Internet permission to your manifest. Check RRR's answer too.

Related

Android Ads with AdMob and Firebase

I'm trying to add a smaller banner image to the bottom of one of the pages in my app. I'm running into a sort of loopy problem:
The code in the XML file is:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.sidekickz.myadventure.activity_hero_picture.xml"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
<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_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
I've tried all variations of xmlns:app/android/ads but I either run into the issue of all the "android" tags not being supported, or something else.
MobileAds.initialize(getApplicationContext(), "appnumber");
AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId("appnumberthing");
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
But at BEST my app shows an image saying that the ad size isn't set. If I follow the suggestions online to alter it, doing so results in Adsize and AdUnitId need to be set before loading.
Any help would be awesome and you would deserve a hug.
Thanks

AdMob banner issues android

I'd like to place ads in my MainActivity below FrameLayout like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:id="#+id/fragmentContainer"
android:layout_centerHorizontal="true">
</FrameLayout>
<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>
I have added this to my Manifest:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
And my build.gradle also looks fine. Here is my java code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(),"ca-app-pub-xxxxxxxx~xxx");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // An example device ID
.build();
mAdView.loadAd(request);
But when I run the app I can't see the ads and in the LogCat I got this errors:
W/Ads: Invalid unknown request error: [Cannot determine request type. Is your ad unit id correct?]
W/Ads: There was a problem getting an ad response. ErrorCode: 1
W/Ads: Failed to load ad: 1
I have tried almost everything I found on the web but nothing worked for me. I think maybe the issue is in my activity_main.xml because of the FrameLayout doesn't give enough place to the ads.
Your code seems fine (although you should call MobileAds.initialize() from the onCreate() method of your Application class, not from an Activity).
Looks like the only problem could be the banner_ad_unit_id resource being an invalid ad unit ID (as the error message also suggests).

Showing error Required XML attribute "adSize" was missing

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.

Admob banner not shown

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.

"linearLayout cannot be resolved or it is not a field" with AdMob instructions by Google for Android

I am trying to find a solution to my problem by an hour and I found some topics with my similar problem, but I don't understand how to resolve.
I was developing an app with Processing for Android and I wanted to try AdMob (just for learning, for now), so I followed instructions all over the net and now I am stuck.
To add ads in the app, I was following Google instructions to add the SDK of Play Service and to add banners, but I am stuck here:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
initPdService();
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pu....83399");
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder()
// .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
// .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
The problem is that it give me "linearLayout cannot be resolved or it is not a field", and I don't know how to resolve. I think that the problem is in findViewById(R.id.linearLayout), since the error is at "linearLayout" and not "LinearLayout".
I am sure that a lot of people find this problem, so I think that is a common problem. I already added import android.widget.LinearLayout;at the top of the sketch, so I don't know what is the problem.
Other infos: it is targeting Android SDK 19, as I know that Play Services want at least API level 13.
EDIT:
Here is my [old] activity_main.xml found is /res/layout:
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<android.support.v7.widget.Space
android:id="#+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginTop="208dp"
android:layout_toRightOf="#+id/adView" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
EDIT 2:
This is my new activity_main.xml, with linearLayout
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<android.support.v7.widget.Space
android:id="#+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginTop="208dp"
android:layout_toRightOf="#+id/adView" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
</RelativeLayout>
You need to set your content view:
setContentView(R.layout.activity_main);
which you have commented out. Do you have an xml file "activity_main.xml" that contains the LinearLayout with an id, linearLayout?
If yout don't have a LinearLayout with the id linearLayout, you need to add one. Otherwise, it's trying to find a view (by id!) that doesn't exist. For example:
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
...
</LinearLayout>
Your issue is that you are using Processing as a library on top of the Android SDK, and it doesn't have access to the layout files, as in Processing you create your screens programatically - it is similar to one big Canvas class for those that are familiar with Android and not Processing.
What the actual compilation error is saying is that the generated R.java file is not finding the compressed resources
I've never tried to add AdMob, but really i think your issue here is that you need to instantiate a LinearLayout programatically, not via XML - as again, you won't have access to that through the PDE.
EDIT:
just noticed that you are using Eclipse (and LibPd !!)... ok, so you can reach a layout
Can you show the code where you are importing Processing into the Activity ?

Categories

Resources