Admob Banner Ad not loading in Android - android

My Admob Banner ad in not loading.
Toast displays that "Banner add is loaded".
I tried many other solutions provided on stackoverflow but none seemed to work for me.
MainActivity.java
public class MainActivity extends AppCompatActivity {
private AdView mBannerAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBannerAd = (AdView) findViewById(R.id.banner_ad);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("A5E3E2068BD88202CBC281AD7XXXXXXX")
.build();
mBannerAd.loadAd(adRequest);
mBannerAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
Toast.makeText(getApplicationContext(), "Closing the Banner Ad", Toast.LENGTH_LONG).show();
}
#Override
public void onAdLoaded() {
Toast.makeText(getApplicationContext(), "Banner Ad is loaded", Toast.LENGTH_LONG).show();
}
});
}
}
activity_main.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/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.akapoor.shayri.MainActivity">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp" />
<com.google.android.gms.ads.AdView
android:id="#+id/banner_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3180111609438244/24179XXXXX" />
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.akapoor.shayri">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShayariText"></activity>
</application>
</manifest>

Assuming that:-
You have complete the steps mentioned here to display a test ad
successfully
This is not a test ad but an actual ad unit.
You have replaced test ad unit ID with the actual ad unit ID
If these steps are done, then It will take an hour or two to get your ad unit displayed in the app.

Your code looks fine. You should remove the test devices, addTestDevice, though:
Change:
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("A5E3E2068BD88202CBC281AD7XXXXXXX")
.build();
to:
AdRequest adRequest = new AdRequest.Builder().build();

Initialize MobileAds in onCreate() like this:
MobileAds.initialize(MainActivity.this,"YOUR_APP_ID));

Related

I put some code of ads and AdMob but cant watch them

I am creating an app and want to add some Google Ads to the main page. I followed all the steps that Google says and don't have any warnings or error, but when I run the app, there isn't any ads.
This is the MainActivity code:
public class MainActivity extends AppCompatActivity {
private FragmentTabHost tabHost;
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//adds
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
This is the xml code of the mainActivity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="35dp"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/mix">
<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>
<Button
android:id="#+id/natacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/button_bg_rounded_corners"
android:onClick="lanzarNatacion"
android:layout_marginTop="80dp"
android:textSize="20dp"
android:text="Natacion" />
<Button
android:id="#+id/carrera"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="lanzarCarrera"
android:background="#drawable/button_bg_rounded_corners"
android:layout_marginTop="80dp"
android:textSize="20dp"
android:text="Carrera" />
</LinearLayout>
This is the mainifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="soloviev.perez.vicente.ritmos">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_mi_icono_"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:roundIcon="#mipmap/ic_mi_icono_"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".carrera" android:label="Calculadora ritmo de carrera" />
<activity android:name=".natacion" android:label="Calculadora ritmo de natacion" />
<activity android:name=".error" android:label="Error" android:theme="#android:style/Theme.Dialog" />
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-4666536989991556~5464124026"/>
</application>
</manifest>
And I added all dependencies and repositories I had to add.
When I run just appear a label which says "Test Ad", but should appear something more.
The codes that i am using are the example codes that Google provides.
Thanks
please add net work permission in manifests
<uses-permission android:name="android.permission.INTERNET"/>
change your code
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
with
mAdView = findViewById(R.id.adView)
AdRequest adRequest = AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build()
mAdView .loadAd(adRequest )
update
log the error code
mAdView.setAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
Log.d("Error code",errorCode.toString());
}
}
and check the error code here
https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_INTERNAL_ERROR
Update
in your gradle
implementation 'com.google.android.gms:play-services-ads:15.0.1'
Add end of your build.gradle(Module:APP)
repositories {
maven { url "https://jitpack.io" }
google()
jcenter()
}
try to update ads dependency
implementation 'com.google.android.gms:play-services-ads:16.0.0'

why I can not see my InterstitialAd?

I am trying to make test ads both InterstitialAd and banner ad with hello world program
the banner add works fine but whe InterstitialAd does not appear when i open my decive on emulator
here is my code :
Androidmainfaist :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zaki.adstrial" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<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"
android:theme="#android:style/Theme.Translucent"/>
</application>
</manifest>
MainActivity:
public class MainActivity extends ActionBarActivity {
private InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitialAd.setAdListener(new AdListener(){
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest2 = new AdRequest.Builder().build();
mAdView.loadAd(adRequest2);
}
activitymain.xml:
<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: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">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<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>
</RelativeLayout>
Where the problem
thanks in advance
i think you have just forgot to load the interstitial ad
before
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
AdRequest.DEVICE_ID_EMULATOR).build();
after
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
AdRequest.DEVICE_ID_EMULATOR).build();
mInterstitialAd.loadAd(adRequest);
You've correctly setup your InterstitialAd, but you didn't load anything to it. Your adRequest2 only loads the data for your banner ad, the mAdView.
That said, you seemingly has also correctly setup another AdRequest for your interstitial; you might just forgot to load it. So, all you need to do is to call this code:
mInterstitialAd.loadAd(adRequest);

Android banner not working

When I run it it gives a java heap space error and again it give message "your project contain errors please fix them before running" and again message display related to "an internal error occured please close workbench". I also use the test id of mobile but same error occurs each time.
Layout file:
activity_main.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/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.google.android.gms.ads.AdView`enter code here`
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize=" SMART_BANNER "
ads:adUnitId="ca-app-pub-7222219345251053/8664557124" />
</LinearLayout>
newadmobtutorialmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbegin.newadmobtutorial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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" />
</application>
</manifest>
mainActivity.java
package com.androidbegin.newadmobtutorial;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
private InterstitialAd interstitial;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from activity_main.xml
setContentView(R.layout.activity_main);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("ca-app-pub-7222219345251053/8664557124");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
// .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
// .addTestDevice("EB81B984CF6F807FED26757A39F8FF")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
and this is my eclipse.ini
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120913-144807
-product
com.android.ide.eclipse.adt.package.adtproduct
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
-vmargs “c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe”
-Dosgi.requiredJavaVersion=1.7
-XX:MaxPermSize=2028m
-XX:CompileThreshold=5
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-Xms2028m
-Xmx6120m
Try to set adUnitId from dynamicly, e.g.
<uradreference>.setAdUnitId("ca-app-pub-7409237681170791/6275305467");
also try with ads:adSize="BANNER" first! It should work.

Admob - Not able to show banner in android app

I am trying to check how admob works.
Till time I am done with including admob like this
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidbannertutorial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<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"/>
</application>
</manifest>
My XML File
<?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:orientation="vertical"
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"
ads:adUnitId="ca-app-pub-4493208dfbf2258768/7749751738 "
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/> -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/ll"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
My main activity class
package com.example.androidbannertutorial;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
/**
* A simple {#link Activity} that embeds an AdView.
*/
public class MainActivity extends Activity {
/** The view to show the ad. */
private AdView adView;
/* Your ad unit id. Replace with your actual ad unit id. */
private static final String AD_UNIT_ID = "ca-app-pub-4493sdf352258768/7749751738";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.ll);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to get test ads on a physical device.
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);
}
#Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
#Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
#Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
Ques: Why we use this .. ???????
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
I have included google_play_lib into my app.
I have my addUnitId : ca-app-pub-4493438885ds9958768/7749751738
Here my banner is not shown up within app.
Only error I am recieving is : The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Even though I have configured with in app.
Can some one help me out what's I extra need to do ?
Thanks.
UPDATE
I am receiving ads after time lapse of 3-4 hours. Can't understand why this behavior occurs ??
Does your code request an Ad? If not then you won't get any ads.
And if you are requesting ads, then you will see evidence of that in the logs as well as the result of the request. Look at your log.
Note also that android:layout_alignParentBottom is not valid for a View within a LinearLayout
Add this in your code:
AdView adView = (AdView) view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);

Admob Banner Ad not displaying in Android

Hi I have a Android game app developed using android cocos2d i need to integrate admob i have included the following code but banner ad is not displaying please help regarding this your answers will be appreciated and it would be a great help. thank you.
public class MainActivity extends Activity {
private CCGLSurfaceView mGLSurfaceView;
private boolean isCreated = false;
public static FrameLayout m_rootLayout;
AdView adView;
// This is used to display Toast messages and is not necessary for your app
#Override
protected void onCreate(Bundle savedInstanceState) {
if (!isCreated) {
isCreated = true;
} else {
return;
}
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
try{
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
adView = new AdView(this, AdSize.BANNER, "admob id");
AdRequest request = new AdRequest();
adView.loadAd(request);
// Adding full screen container
addContentView(adView, adParams);
}catch (Exception e) {
FlurryAgent.logEvent("ADMOB ERROR: "+e);
}
mGLSurfaceView = new CCGLSurfaceView(this);
setContentView(mGLSurfaceView);
CCDirector.sharedDirector().attachInView(mGLSurfaceView);
getScaledCoordinate();
Global.assetManager = getAssets();
Global.context = this;
Global.loadUserInfo();
CCScene scene = CCScene.node();
scene.addChild(new SplashScene(), -1);
CCDirector.sharedDirector().runWithScene(scene);
//-------------IAP-----------------------
Log.d(TAG1, "Creating IAB helper.");
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
Log.d(TAG1, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
complain("Problem setting up in-app billing: " + result);
return;
}
// Hooray, IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d(TAG, "Setup successful. Querying inventory.");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
Global.myActivity=this;
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game.puzzlegame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.game.puzzlegame.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.revmob.ads.fullscreen.FullscreenActivity"
android:configChanges="keyboardHidden|orientation" >
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>
</application>
Please review all these additions in your project.
In Java class:
AdView layout = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
//adRequest.setTesting(true);
layout.loadAd(adRequest);
In Layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="your key" />
</LinearLayout>
In Manifest:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation" />
I have worked with AdMob Lib. Ver. 4.0.4 which worked fine in my case.
Try this code
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
AdView ad = new AdView(this, AdSize.BANNER, "admob_id");
adParams.addView(ad);
AdRequest r = new AdRequest();
//r.setTesting(true);
ad.loadAd(r);
Make sure that you included correct ID and have correspond permissions for your app.
In addition it would be good to implement ADListener that really displays what how its going with ads rendering.
Also don't forget to set test mode to query ads, AdMob guys can just ban you for irresponsible clicks.
for latest Ads in Android
use below code
AdView layout = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
//adRequest.setTesting(true);
layout.loadAd(adRequest);
beacuse AdRequest class final class so we can not create object.

Categories

Resources