Hello in my app i'm using "Admob" banner when i running the aplication on my device i see the Advertisement and it's works but in the xml file is see the banner with a message like "AdView missing required XML attribute 'adSize'” . but when it's running it's look like it working fine. Why is that? And is it important to treat it? or just ignore it?
(i searched about my question on the web but i think my problem is a little different)
Xml:
<com.google.android.gms.ads.AdView
android:id="#+id/ad"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginTop="300dp"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXXXXXXXXXXXXXXXXX"
/>
manifest:
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
MainActivity:
public void adMob(){
adView = (AdView)v.findViewById(R.id.ad);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
Related
I am trying to add ads to my android app. Its going well, and I see the layout showing up. The problem is, when I try to request the app through the onCreate function in my main java file it crashes.
Here is the code I am adding when it crashes:
Xml file
<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="ID">
</com.google.android.gms.ads.AdView>
Java file:
//request and load the ad.
AdView mAdView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Manifest file:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent">
</activity>
Please help me
Description:-
I am integrating my App with "Google Play Service" SDK as per latest guidelines from Google.
earlier it was integrated with standalone admob SDK.
ISSUE:-
Banner ads and Full ads are shown properly when one of them are shown. But when both has to be shown, they give unpredictable results.
Unpredictable results?
Yes, sometime only Banner is loading and sometime only Full ad is shown. it is very rare that both of them are shown.
FIX:-
1. I tried giving some delay between Banner and interstitial and got little better results. But still results are unpredictable most of the time.
I used Asynch task for Full ads. Gave some delay of 2 seconds in Background() and loaded the ad in PostExecute(). It give much better results. But still out of 10 attempts, only 7 times both the ads are shown. rest of the 3 times either Banner or Full or none of them is loaded.
Following is the code of Main activity
package com.example.adtest_new;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
public class MainActivity extends Activity
{
Context myCont=null;
private InterstitialAd interstitial = null;
AdRequest adr;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Get the view from activity_main.xml
setContentView(R.layout.activity_main);
myCont = this;
//--------------BANNER AD----------------------------------
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder().build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
//--------------BANNER AD----------------------------------
//Fix-1 (Did not work)
try{Thread.sleep(2*1000);}catch(Exception e){}
//Fix-2 (Did not work)
//Called Asynch task here(put delay of 2 seconds in background() and loaded full ad in postexecute())
//--------------FULL AD----------------------------------
//Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
//Insert the Ad Unit ID
interstitial.setAdUnitId("ca-app-pub-465697675827xxxx/xxxxxxxxxx");
adr = new AdRequest.Builder().build();
//Load ads into Interstitial Ads
//Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener()
{
public void onAdLoaded()
{
//System.out.println("!!! Full Ad loaded !!!");
Toast.makeText(myCont, "!!! Full Ad loaded !!!", Toast.LENGTH_SHORT).show();
//Call displayInterstitial() function
displayInterstitial();
}
});
interstitial.loadAd(adr);
//--------------FULL AD----------------------------------
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded())
{
interstitial.show();
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/openedWindows"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="#+id/completePath"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="0dp"
android:layout_marginLeft="3dp"
android:text="/mnt/sdcard"
android:textColor="#ff2d8df1"
android:textSize="16dip"
android:textStyle="bold"
android:typeface="sans"/>
<View
android:id="#+id/bar0"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="0dp"
android:background="#ffb2cb39"
android:layout_marginBottom="0dp"/>
<View
android:id="#+id/bar1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="0dp"
android:background="#ffb2cb39"
android:layout_marginBottom="1dp"/>
<RelativeLayout
android:id="#+id/temp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<Button
android:id="#+id/selectAll"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="left"
android:layout_marginBottom="1dp"
android:layout_marginLeft="15dp"
android:layout_alignParentLeft="true"
android:background="#drawable/button_green"
android:textSize="15dip"
android:text="BUTTON1"
android:paddingLeft="10px"
android:paddingRight="10px"
android:textColor="#ffffff"
android:textStyle="bold" />
<Button
android:id="#+id/selectBtn"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="1dp"
android:layout_alignParentRight="true"
android:background="#drawable/button_green"
android:textSize="15dip"
android:text="BUTTON2"
android:paddingLeft="10px"
android:paddingRight="10px"
android:textColor="#ffffff"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_above="#+id/tableRow2"
android:background="#444444"
android:layout_marginBottom="0dp"/>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-465697675827xxxx/xxxxxxxxxx"
/>
</TableRow>
</LinearLayout>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adtest_new"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
</application>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
Kindly let me know how to resolve this??
Standalone admob SDK is working fine for both of the ad types.
I see that you are loading "real" ads (ie not test ads), as you do not declare test devices. I am not 100% sure about what I am going to say, but this could perhaps be the cause of the problem. When displaying real ads, I think you will not always have available ads from Admob/Google Play Services, so sometimes you will not have ads displayed (I think the loading error code is 3, which is "no fill"). You could test while declaring test devices, which cause the use of test ads that are always available.
In addition it is recommended to use test devices while developping, because if you click a lot on your own ads (by mistake or just to test) you may be banned from AdMob.
To see how to add test devices, cf this
Test ads
You should use test ads during development to avoid generating false
impressions. Additionally, you can always count on a test ad being
available. Set up test ads by passing your hashed Device ID to
AdRequest.Builder.addTestDevice: AdRequest request = new
AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") // My Galaxy Nexus test phone
.build();
logcat will print the dev
ice's MD5-hashed ID for convenience, for example: Use
AdRequest.Builder.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") to
get test ads on this device.
(https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner)
Take care that some people say that test ads do not work properly if your phone is not in English (AdMob test ads shows only on English devices)
Edit : Of course real users of your app will use the real ads, so they may also experience the "problem" of not always ads available, but this is normal. You can still regurlarly Schedule new loads (for the interstitial, the banner reloads itself regularly) to try to cope with that I guess.
Edit 2 : By the way, this may be a little irrelevant to your problem, but people usually strongly advise to no display the ad from the AdListener.onAdLoaded method, but to invoke this manually at the moment your want it to be displayed (if isLoaded is true). But this is only an ergonomy consideration, no a bug-Wise one
I am trying to integrate admob to my android app using new google play services sdk. But ads are not visible. It showing warning in log cat that > Not enough space to show ad. Needs 480X75 pixels, but only has 540X0. I used same code that given on android developer page.
code added in manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|
orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
code in main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/adViewl"
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="match_parent"
ads:adSize="BANNER"
ads:adUnitId="AD_UNIT_ID" />
</LinearLayout>
and java code
LinearLayout layout = (LinearLayout) findViewById(R.id.adViewl);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("AD_UNIT_ID");
layout.addView(adView);
//AdRequest adRequest = new AdRequest.Builder().build(); // Start
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Please, tell me where i am wrong in above code.
The error is "only has 540X0" which means the AdView has no height available.
If the layout given above is the only content of main.xml then you must be using a theme that has somehow reduced the size of the AdView or the LinearLayout to zero.
finally, i got solution to my problem by changing java code. I removed linear layout code from java code. Used only Adview as given below,
AdView adView = (AdView) findIdByValue(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
^ there is the image so you know I'm using sdk 3.2. There is more to this code, but basically this is everything for my java code inside my main one, and it doesn't load my ads when I go to load them. There are no errors and nothing in my Main.XML for the ad Basically the ad is not showing at all
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class LearningLettersActivity extends Activity
private AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "aXXXXXXXXXXXXXXXX); //<---My Publisher Id there"
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout" \
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
Here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.better.work.learning.letters.and.more"
android:versionCode="3"
android:versionName="1.00">
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity
android:name=".LearningLettersActivity"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk android:minSdkVersion="4"/>
</manifest>
Basically nothing is pooping up for my ads at all when I go to test it on my phone, I tried using the code below and still nothing.
AdRequest adrequest = new AdRequest();
adrequest.setTesting (true);
adView.loadAd(adrequest);
I've also tried:
AdRequest adrequest = new AdRequest();
adrequest.setTesting (true);
adrequest.setTestingDevices("HT0CWHL11423") //<--- the name of my phone that appears when I go to load the emulator tab
adView.loadAd(adrequest);
Result:
01-18 03:50:19.874: E/Ads(16938): Could not find com.google.ads.AdActivity, please make sure it is registered in AndroidManifest.xml.
01-18 03:50:19.874: E/Ads(16938): You must have AdActivity declared in AndroidManifest.xml with configChanges.
Look in the logcat for anything with the Tag Ads. Specifically, look for something like:
Ad Request successful, but no ad returned due to lack of inventory.
It is possible that you are not getting ads back because AdMob cannot fill an ad.
There are a couple of things to note here. AdRequest.setTesting(true), which only used to set test mode for emulators, is deprecated in favor of AdRequest.addTestDevice(AdRequest.TEST_EMULATOR) for setting test mode on an emulator. For setting a test device, the device id you are supposed to enter is a hashed device id, which you can find in the logcat as well if you are debugging on your device.
Finally, the picture that you're using shows you have the SDK included for a ButtonMasher app, but the code you provided looks like it's for a Letter Learning app. Make sure you are indeed using 4.3.1 in this app.
The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).
So take android v3.2 as your target version for the latest copy (as your manifest file suggest that you have taken the latest one).
For more details please have a look on this
Hope this will help you.
I am at my wits' end. I have a special LinearLayout for ads
<LinearLayout
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="52dp"
>
</LinearLayout>
I fill it with ads from the code
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
LinearLayout bout = (LinearLayout) findViewById(R.id.layout1);
bout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
Manifest file looks like this
<!--Permissions-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
/>
And the JAR GoogleAdMobAdsSdkAndroid-4.1.1 is added to the path.
No ads EVER show up. In Logcat I see that
08-23 12:03:04.527: WARN/Ads(28980): IOException connecting to ad url.
08-23 12:03:04.527: INFO/Ads(28980): onFailedToReceiveAd(A network
error occurred.)
I test this on a real device.
Any suggestions?
With the latest version of admob (4.1 i think) the easy form to put admob ads is with xml. You only should put :
//At the beginin of the xml
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
<com.google.ads.AdView
android:id="#+id/Ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14daeadccXXXXX"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
Then the permision and remember dont put padding to de linearlayout or the ads dont appear.
It seems that Manifest file still NEEDS meta data, although the official docs do not say anything about it. So in the manifest file add the meta data (besides other data) and the ads will show up
<application android:label="App Name" android:icon="#drawable/icon">
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="XXXXXXXXXXXXXX"
>
</meta-data>
...
I came up to this conclusion by implementing AdListener and adding Log messages into it. I suggest you do the same in case you need to closely investigate what is going on when an ad has been received.