Reputation: 25
I have created an application for admob, but I am getting an error. I found an example from Google and I have tried it, but there is a problem when I'm launching the application .
I'm using Android 2.2 API 8. I am able to launch the application, but this block is causing an error.
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
If I change this to
android:configChanges="keyboard|keyboardHidden"
then I am able to launch the application, but there is an error coming on our add field.
you must have adactivity declare in Android Manfiest.xml with config change
Due to this I am not able to show google adds in our application.
Please help me to fix this.
Upvotes: 0
Views: 733
Reputation: 732
- AdActivity.java
package com.android.ads;
import android.app.Activity;
import android.os.Bundle;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class AdsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdView adview = (AdView) findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setTesting(true);
re.setGender(AdRequest.Gender.FEMALE);
adview.loadAd(re);
}
}
- main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.android.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="Your adunit ID"
android:layout_alignParentBottom="true"/>
</LinearLayout>
Remember Put GoogleMapAdmobSdk.jar after creating libs folder for Configure build path
Create the attrs.xml in the Values folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.google.ads.AdView">
<attr name="adSize">
<enum name="BANNER" value="1"/>
<enum name="IAB_MRECT" value="2"/>
<enum name="IAB_BANNER" value="3"/>
<enum name="IAB_LEADERBOARD" value="4"/>
</attr>
<attr name="adUnitId" format="string"/>
</declare-styleable>
</resources>
- AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.ads"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AdsActivity"
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.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
</manifest>
Your work is done buddy............
Upvotes: 0
Reputation: 10542
I guess you just have to follow this tutorial.
And escpecially your problem should be about this lines:
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).
that means that minSDK can be down to 1.5 but you have to compile on 3.2 at least.
Upvotes: 2
Reputation: 2076
from AdMob documentation
you need to add the entire activity tag to AndroidManifest.xml
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
see https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals
Upvotes: 0