Add advertisement for Android App

Source: Internet
Author: User

Adding advertisements to Android apps is one of developers' incomes. However, apps with advertisements are quite disgusted with users and many things are in conflict. How can we add advertisements to our apps? The mobile advertisement platform provides the corresponding SDK. You only need to download their SDK and add it according to their development documents.

Below are some advertisement platforms:

1. Baidu Mobile Alliance: http://munion.baidu.com/

1. Baidu Mobile Alliance promotion SDK download: http://munion.baidu.com/about.html#/sdk/mobSdk

2. Baidu mobile Union integral wall SDK download: http://munion.baidu.com/about.html#/sdk/statSdk

2. meters: http://www.youmi.net/

There are other advertising platforms such as domob, limei, and cogoe.

For more information about mobile ad platforms, see: http://baike.baidu.com/link? Url = Response

The following is an example of my use of Baidu promotion SDK. In fact, it is the same as the example provided by Baidu, But I practiced it myself.

First download the Baidu promotion SDK package and decompress the Directory


In the baibaidu_mobads_sdk_manual.doc document, teach you how to add an advertisement to your APP.

Directory structure <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140410/2014041009321272.png" alt = "\">

Declare permissions and activities in the AndroidManifest. xml file

 
     
      
      
      
      
      
      
      
      
      
      
      
      
      
              
          
                                                              
                                  
               
              
 

During debugging, we recommend that you set the value of APPSID and billing name to debug for AD debugging. After successful debugging, you must change your APPSID and billing name and upload the application to the Consortium for review. After the application is approved, you will be charged, if the application is not approved and the value of APPSID and billing name is not debug, no advertisement is displayed.

AdActivity. java

Package com. dzt. baidu; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button;/*** use Baidu promotion example dzt ** @ author Administrator 2014.04.09 **/public class AdActivity extends Activity implements OnClickListener {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initWidgets ();} private void initWidgets () {Button btn = (Button) findViewById (R. id. simple_declaring); btn. setOnClickListener (this); btn = (Button) findViewById (R. id. simple_coding); btn. setOnClickListener (this); btn = (Button) findViewById (R. id. simple_inters); btn. setOnClickListener (this); btn = (Button) findViewById (R. id. simple_icon); btn. setOnClickListener (this) ;}@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubswitch (v. getId () {case R. id. simple_declaring: StartActivity (DeclaringActivity. class); break; case R. id. simple_coding: StartActivity (CodingActivity. class); break; case R. id. simple_inters: StartActivity (InterstitialActivity. class); break; case R. id. simple_icon: StartActivity (iconsactyworkflow. class); break; default: break;} private void StartActivity (Class
 Cls) {Intent intent = new Intent (AdActivity. this, cls); startActivity (intent );}}
Corresponding xml file

     
      
      
      
      
  
 

There are two ways to add banner banners

I. Add code

Package com. dzt. baidu; import org. json. JSONObject; import com. baidu. mobads. adSettings; import com. baidu. mobads. adSize; import com. baidu. mobads. adView; import com. baidu. mobads. adViewListener; import android. app. activity; import android. OS. bundle; import android. util. log; import android. widget. relativeLayout; public class CodingActivity extends Activity {private static final String TAG = "dzt"; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); // setContentView (R. layout. coding); // group attributes AdSettings. setKey (new String [] {"baidu", "China"}); AdSettings. setCity ("Shanghai"); AdSettings. setZip ("123456"); AdSettings. setJob ("engineer"); AdSettings. setEducation (AdSettings. education. BACHELOR); AdSettings. setSalary (AdSettings. salary. f10kT15k); AdSettings. setHob (new String [] {"badminton", "soccer", "baseball"}); RelativeLayout rlMain = new RelativeLayout (this ); // create an advertisement ViewAdView adView = new AdView (this, AdSize. banner, "01"); // sets the listener adView. setListener (new AdViewListener () {public void onAdSwitch () {Log. w (TAG, "[CodingActivity]-> onAdSwitch");} public void onAdShow (JSONObject info) {Log. w (TAG, "[CodingActivity]-> onAdShow" + info. toString ();} public void onAdReady (AdView adView) {Log. w (TAG, "[CodingActivity]-> onAdReady" + adView);} public void onAdFailed (String reason) {Log. w (TAG, "[CodingActivity]-> onAdFailed" + reason);} public void onAdClick (JSONObject info) {Log. w (TAG, "[CodingActivity]-> onAdClick" + info. toString ();} public void onVideoStart () {Log. w (TAG, "[CodingActivity]-> onVideoStart");} public void onVideoFinish () {Log. w (TAG, "[CodingActivity]-> onVideoFinish") ;}@ Overridepublic void onVideoClickAd () {Log. w (TAG, "[CodingActivity]-> onVideoClickAd") ;}@ Overridepublic void onVideoClickClose () {Log. w (TAG, "[CodingActivity]-> onVideoClickClose") ;}@ Overridepublic void onVideoClickReplay () {Log. w (TAG, "[CodingActivity]-> onVideoClickReplay") ;}@ Overridepublic void onVideoError () {Log. w (TAG, "[CodingActivity]-> onVideoError") ;}}); rlMain. addView (adView); setContentView (rlMain );}}
Ii. Add an xml file

 
     
      
  
 
Xmlns: baiduadsdk = "http://schemas.android.com/apk/res/com.dzt.baidu" where com. dzt. baidu is your app package name, xmlns: baiduadsdk is the property domain of the custom control

Corresponding attribute file attrs. xml

 
 
   
 

Corresponding Demo: http://download.csdn.net/detail/deng0zhaotai/7168479




Related Article

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.