-
Notifications
You must be signed in to change notification settings - Fork 4
Interstitial Integration
Banner ads usually appear at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.
Before integrating banner ads in your app, you’ll need to go through the steps in our Getting Started Guide to integrate the SDK into your project. #Sample code And obtain Banner Ads Steps
obtain sample code:
For a complete example, check out the CMAdSDK-sample.
obtain Banner Ads Steps:
1.Define a Layout XML for your banner ad.
2.Create CMNativeBannerView and set the size of banner or posId of banner
3.set callback interface which is CMBannerAdListener
4.load banner ad and display banner ad
5.if the acitivity destory , suggest destory the banner view
#Load banner ads in your app ###1. Check your AndroidManifest.xml file Be sure you have the following permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />**Note:**The INTERNET permission is required which is used to access the internet to get ad. The ACCESS_NETWORK_STATE or ACCESS_WIFI_STATE permission are optional which used for checking whether there is avaible Internet connection(suggest configure them).
if you integrated PEGASI SDK Ext Version , Please declare the following activities:
<!--for Mopub -->
<activity android:name="com.mopub.mobileads.MoPubActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.common.MoPubBrowser"
android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
<!--for Mopub-->Add this tag to your to use Google Play Services:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />Important Note: If compiling against API Level below 13, exclude screenSize from the manifest entries.
###1.Define a Layout XML for your banner ad. note: Start by including this XML block to your Activity’s or Fragment’s layout,The layout can be FrameLayout , LinearLayout etc. res/layout/native_ad_layout.xml
<FrameLayout
android:id="@+id/origin_picks"
...
/>###2.Create CMNativeBannerView and set the size of banner or posId of banner
CMNativeBannerView bannerView = new CMNativeBannerView(Context);
bannerView.setAdSize(CMBannerAdSize);
bannerView.setPosid(mAdPosid);Note: bannerSize,only support CMBannerAdSize.BANNER_300_250 or CMBannerAdSize.BANNER_320_50
###3.set callback interface which is CMBannerAdListener
bannerView.setAdListener(new CMBannerAdListener() {
@Override
public void onAdLoaded(CMAdView adView) {
//load success , do other operator
}
@Override
public void adFailedToLoad(CMAdView adView, int errorCode) {
//load failed
}
@Override
public void onAdClicked(CMAdView adView) {
}
});###4.load banner ad and display banner ad start load banner ad:
bannerView.loadAd();display banner ad:
public void onAdLoaded(CMAdView ad) {
mLayoutContainer.removeAllViews();
mLayoutContainer.addView(ad);
}@Override
protected void onDestroy() {
super.onDestroy();
if(cmNativeBannerView != null){
cmNativeBannerView.onDestroy();
}
}