Android App Add ads Tutorial

Source: Internet
Author: User

Get Android AD Management Library

to display ads in the mobile app, you need to add an ad management library in the app, the current version of the Keymob AD Management library is 20150801 downloads to see the Android project directory structure, most of the regular Android engineering files and directories, The following resources are related to the Keymob Management library. Download the AD Management Library

    • README.MD keymob English Quick Integration documentation

    • README_ZH.MD keymob Chinese Quick Integration documentation

    • Libs

      • Keymobad.jar Keymob Advertising Management Core Library

    • Assets

      • Com_keymob_sdks Keymob Standby Platform

      • Biduad_plugin Keymob Baidu Platform needs resources

      • Gdt_plugin keymob Wide-point platform required Resources

Note: Three folders under the assets directory and files under the folder cannot modify the name

Com_keymob_sdks Directory There is a admobadapter.jar that keymob use AdMob as an alternate ad platform when you can't connect keymob if you want to switch to a different platform, you can download more backup platforms.
In addition to the resources downloaded above, use Keymob's officially supported platform, eliminating the need to add separate code for each platform

Add management library to eclipse project

The following steps are required to add a use AD management library

    1. Copy the downloaded Keymobad.jar to your own Android project under the Libs

    2. Copy the downloaded Com_keymob_sdks to your own Android project under the assets

    3. If you want to use the Baidu advertising platform, copy the downloaded Biduad_plugin to your Android project assets

    4. If you want to use the wide-point platform, copy the downloaded Gdt_plugin to your Android project's assets

Add ad-related Java code 1. First Import Keymob related classes
Import Com.keymob.ads.AdManager;    Import com.keymob.core.*; Import Com.keymob.sdk.core.AdTypes;
2. Initialize Keymob

Initializing the Keymob management library is a prerequisite for invoking other ad function functions, which must be initialized before making any other calls, and the following are the initialization methods using the Keymob.com service

Admanager.getinstance (). Initfromkeymobservice (This, "1", New Adeventlistener (), false);
    • Parameter description

    • This is the first argument this is an ad context, not a null

    • The second parameter of "1" is the Keymob app ID, the app ID that was obtained after keymob.com registered to create the app

    • Adeventlistener Advertisement Event processing class, Implement Interface Iadeventlistener, if you do not plan to process AD events can be null

    • False if it is a test mode, set to True when developing debugging, and false when publishing.

3. Display Ads

Below the show banner ads in absolute position (0,200) example

Admanager.getinstance (). Showbannerabs (Bannersizes.banner, 0, 200);
    • Parameter description

    • Bannersizes.banner the first parameter ad size, all the default supported banner sizes are in the Bannersizes class

    • "0" The second parameter is the location of the ad X

    • "200" The second argument is the location of the ad Y

4. Add AD rights

Edit Androidmanifest.xml Add the required permissions to the app, such as a network request, and the following are the permissions required for most AD platforms

<!-- base permission --><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= "Android.permission.READ_PHONE_STATE"/><!-- base permission  for location--><uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"  /><uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"  />  <!-- base permission  required by chartboost and baidu-->< Uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/><!-- permission  required by mmedia --><uses-permission android:name= "Android.permission.RECORD _audio " /><uses-feature android:name=" Android.hardWare.microphone " android:required=" false " /> 
5. Add configuration information such as AD activity

Edit Androidmanifest.xml activity to add an ad platform to your app, activity with no platform added will not show platform ads

<meta-data android:name= "Com.google.android.gms.version"
Android:value= "7327000"/>
<activity
Android:name= "Com.google.android.gms.ads.AdActivity"
Android:configchanges= "Keyboard|keyboardhidden|orientation|screenlayout|uimode|screensize|smallestscreensize"
Android:theme= "@android: Style/theme.translucent"/>

<!--Amazon Mobile Ads--
<activity android:name= "Com.amazon.device.ads.AdActivity"
android:configchanges= "Keyboardhidden|orientation|screensize"/>

<!--InMobi--
<activity android:name= "Com.inmobi.androidsdk.IMBrowserActivity"
Android:configchanges= "Keyboardhidden|orientation|keyboard|smallestscreensize|screensize"
Android:theme= "@android: Style/theme.translucent.notitlebar"
Android:hardwareaccelerated= "true"/>

<!--millennial Media--
<activity android:name= "Com.millennialmedia.android.MMActivity"
Android:theme= "@android: Style/theme.translucent.notitlebar"
Android:configchanges= "Keyboardhidden|orientation|keyboard|screensize" ></activity>

<!--Keymob--
   <activity android:name= "com.keymob.sdk.core.KeymobActivity"   Android:theme= "@android: Style/theme.dialog"
   android:configchanges= "keyboard|keyboardhidden| Orientation|screenlayout|uimode|screensize|smallestscreensize "
   />
   <!-- Baidu--
   <activity android:name= "com.baidu.mobads.AppActivity" android:configchanges= " Keyboard|keyboardhidden|orientation "/>

<!--AdColony--
   <activity android:name= "Com.jirbo.adcolony.AdColonyOverlay" Android: Configchanges= "Keyboardhidden|orientation|screensize"
   android:theme= "@android: style/ Theme.Translucent.NoTitleBar.Fullscreen "/>
   <activity android:name=" Com.jirbo.adcolony.AdColonyFullscreen "android:configchanges=" keyboardhidden|orientation|screensize "
   android:theme= "@android: Style/theme.black.notitlebar.fullscreen"/>
   <activity Android : Name= "Com.jirbo.adcolony.AdColonyBrowser" android:configchanges= "Keyboardhidden|orientation|screensize"
   android:theme= "@android: Style/theme.black.notitlebar.fullscreen"/>

<!--Guang Dian Tong--
<service android:name= "Com.qq.e.comm.downloadservice" android:exported= "false"/>
<activity android:name= "com.qq.e.ads.adactivity" android:configchanges= "keyboard|keyboardhidden|orientation| ScreenSize "/>

More mobile app Access advertising tutorials QQ Exchange Group 310513042 back to Home


Android App Add ads Tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.