I am facing trouble in displaying Ads in my Phonegap App, as getting the error message - " you must have adactivity declared in androidmanifest.xml with configchanges "
Here is my manifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyApp"
android:versionCode="5"
android:versionName="1.3.1" >
<supports-screens
android:largestWidthLimitDp="320"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:debuggable="false"
android:allowBackup="true"
android:icon="@drawable/desktop_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.MyApp.Activity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|screenSize|locale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- AdMobActivity definition -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize"/>
</application>
</manifest>
The library that I have used for using Admob is GoogleAdMobAdsSdk-6.4.1.jar
The similar code is working in normal activity (without using phonegap), but facing trouble while embedding admob in phonegap.
old version admob sdk is not supported by android .you can try use other plugins. ref: https://github.com/admob-google/admob-cordova
use the cordova command
download the plugin ,then install with local location
cordova plugin add c:\phonegap-admob-plugin
or install cordova plugin online
cordova plugin add com.admob.plugin
use the phonegap command
download the plugin ,then install with local location
phonegap plugin add c:\phonegap-admob-plugin
use phonegap builder ,add config
<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>
init plugin after deviceready event
admob.initAdmob("admob banner ID","admob interstitial ID");//admob id format ca-app-pub-xxxxxxxxxxxxxxxxxxx/xxxxxxxxxx
there are some banner size in admob.BannerSize,and you can create your own banner size that is available in admob platform. admob.Position hold all relation position const .
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP);//show banner at the top of app
and more you can set more param for admob such as test mode and is your app made for child. var admobParam=new admob.Params(); //admobParam.extra={'keyword':"admob phonegame"}; //admobParam.isForChild=true; admobParam.isTesting=true; admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_CENTER,admobParam);
you can put admob banner at absolute position as easy as relation position.
admob.showBannerAbsolute(admob.BannerSize.BANNER,0,70);//show banner at absolute position x 0,y 70
show admob Interstitial in phonegap,cordova or xdk application is the same step. cache Interstitial ,and then show it in onInterstitialReceive function or show it when your game over. ```
document.addEventListener(admob.Event.onInterstitialReceive, onInterstitialReceive, false);//show in ad receive event fun need add receive listener
admob.cacheInterstitial();// load admob Interstitial
function onInterstitialReceive(message) {//show in ad receive event fun
admob.showInterstitial();
}
function onGameOver(){//call this fun to show when game over
admob.isInterstitialReady(function(isReady){
if(isReady){
admob.showInterstitial();
}
});
}
```
you can handler all native event of admob ,as onInterstitialReceive
all event type is in admob.Event
```
function onAdmobEvent (message) {
//do some on admob event
}
document.addEventListener(admob.Event.onAdmobBannerDismiss, onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobBannerFailedReceive), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobBannerLeaveApplication), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobBannerPresent), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobBannerReceive), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobInterstitialDismiss), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobInterstitialFailedReceive), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobInterstitialLeaveApplication), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobInterstitialPresent), onAdmobEvent, false);
document.addEventListener(admob.Event.onAdmobInterstitialReceive), onAdmobEvent, false);
```
1.hide admob banner
admob.hideBanner()
2.test if Interstitial has loaded success ```
admob.isInterstitialReady(function(isReady){
if(isReady){
alert("admob Interstitial loaded");
}
});
```
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.