When i place my pub id
AdView adView = new AdView(this, AdSize.BANNER, Publisher ID);
and
layout.addView(adView);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
iam getting the ads but when i set it to
request.setTesting(false)
i am not getting ads how to solve this.. what is the actual prob;lem?
Use this in your activity:
adview = (AdView) findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.addTestDevice(AdRequest.TEST_EMULATOR); // Emulator
re.addTestDevice("xxxxxxxxxxx"); // Test Android Device
adview.loadAd(re);
Use this in your XML file:
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxx"
ads:loadAdOnCreate="true">
</com.google.ads.AdView>
Add the banner in XML it is much easier !
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
and in the activity put only
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
Related
It is not a duplicate question. I already tried solutions from similiar questions but none of them worked.
My Google Ad Banner code is below:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/konstraitLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="0dp"
app:layoutDescription="#xml/activity_main_scene"
tools:context=".MainActivity">
...
<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"
ads:adSize="Banner"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
...
</androidx.constraintlayout.widget.ConstraintLayout>
The code in MainActivity:
adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
So I added my banner in XML. I found it in java and then called it, but I guess I am missing something since I've got the following error:
The ad size and ad unit ID must be set before loadAd is called
Thanks for answer.
The adSize tag should have its value passed in capital letters. Replace this:
ads:adSize="Banner"
with this:
ads:adSize="BANNER"
Im trying to add a banner to my Android application, but can't get it to work. The banner is visible in the preview but not when running on my Genymotion device. This is my layout-file:
<LinearLayout 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"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.my.package.MapsActivity"
tools:layout="#android:layout/list_content"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="450dip"
tools:context="com.example.my.package.MapsActivity"/>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"/>
</LinearLayout>
And in the Activity-file I have this code:
MobileAds.initialize(mContext, "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
It does not work with test ads either. What can be wrong?
Hank
One thing I would like to say that whenever you create a banner or interstitial than you have to wait for few hours for ads to display on your mobile screen.
Maybe your gmail account used in the Genymotion is the same with admob account. Try change to another gmail in your Genymotion.
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
I try add admob Ads in my app. Initial I add code :
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("abc")
.build();
adView.loadAd(adRequest);
but it not run, it show error
11-23 11:16:20.285: E/AndroidRuntime(24361): FATAL EXCEPTION: main
11-23 11:16:20.285: E/AndroidRuntime(24361): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.phohaycom/com.example.phohay.activity.ReadingActivity2}: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
So I try add code :
AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId("ca-app-pub-1845170371498416/12345678");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("D5AF9D9AFD269EF3B817CD9804BF2CE9")
.build();
mAdView.loadAd(adRequest);
It run but when I run it, it not show Ads which only displays text "Either XML attribute "ad Size" or XML attribute "supported Ad Sizes" should be specified, but not both.
My xml file :
<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="match_parent"
android:background="#ffffff" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
it fails anywhere? Please help me
I think remove either of ads:adSize="BANNER" or mAdView.setAdSize(AdSize.BANNER); will help.
I have done it.
I don't add code in xml. Instead I create Linear Layout and add Ads in code
AdView adView = new AdView(getApplication());
adView.setAdUnitId("ca-app-pub-1845170371498416/123456789");
adView.setAdSize(AdSize.BANNER);
LinearLayout adLinLay = (LinearLayout) findViewById(R.id.Llayout);
adLinLay.addView(adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
"D5AF9D9AFD269EF3B817CD9804BF2CE9").build();
adView.loadAd(adRequest);
Thank everyone! good luck
Can you please try this one ? :
Remove this one:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
Delete the xmlns:ads*** tag
Add this one:
xmlns:ads="http://schemas.android.com/apk/res-auto"
xml file should looks like below:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello"/>
<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="INSERT_YOUR_AD_UNIT_ID_HERE"/>
</LinearLayout>
Hope this will help you.
I had declared google ads in xml as
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.admobdemo"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="a150cb2e31846cf"
ads:loadAdOnCreate="true"
ads:testDevices="AVD_for_4in_WVGA_Nexus_S,5554" />
</RelativeLayout>
I have declared the namespace in XML and in manifest file also.
And i am declaring in my activity as
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adRequest.setTesting(true);
adView.loadAd(adRequest);
But when i run my app i am getting the RESPONSE as
adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"u_w":480,"simulator":1,"msid":"com.netserv.Pungry","cap":"m,a","js":"afma-sdk-a-v4.0.2","isu":"B3EEABB8EE11C2BE770B684D95219ECB","format":"320x50_mb","net":"ed","app_name":"4.0.2.android.com.netserv.Pungry","hl":"en","u_h":800,"testing":1,"u_so":"p","u_audio":4});</script></head><body></body></html>
But it's not displaying in the output and i am getting error as
03-19 13:43:46.190: E/Ads(4983): AdView missing required XML attribute adUnitId.
Can i know what is the error in my code.
Thanks:)
Take one layout in main layout when you want to show ad
<LinearLayout
android:id="#+id/addlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
and in java file
AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxxxx");
LinearLayout addLay = (LinearLayout) findViewById(R.id.addlay);
AdRequest adRequest = new AdRequest();
// adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
addLay.addView(adView);
adView.loadAd(adRequest);
Did you check this
Also some times project clean also works ..
Are you able to see this