Android Tencent Advertising Alliance Access-----banner advertising

emmm this time, I am connected to Tencent's opening screen advertisement


Old rules first on the renderings

                        


The first three steps are the same as the opening advertisement, so I just use it directly

One: Preparation

  1. Of course, now you have to register a Tencent Advertising Alliance account. The registration address is: http://e.qq.com/dev/index.html
  2. Fill in all the information and download his Android SDK // In fact, it is the standard version
  3. Enter the advertising space, find his advertising ID and application ID, remember the ones you will use later and don't mix them up //This is the ID of the banner advertisement, don't use it wrong!

Two: SDK for accessing advertisements

  1. First unzip the downloaded advertising SDK compressed package. The resources folder contains some image resources, which are basically useless. Find the Jar package of the SDK as shown in the figure below.                  This is the jar package we will use and copy it to the app. /libs directory and then sync
  2.  Then we go to the next step to make a declaration in AndroidManifest.xml
  3. <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"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

      4. Add the following to the <application> tag

<!-- Tencent declares the components required by the SDK-->
 < service
 android :name= "com.qq.e.comm.DownloadService"
 android :exported= "false" >
 </ service >
 <!-- Please developers Note the capitalization of letters, ADActivity, not AdActivity -->
 < activity
 android :name= "com.qq.e.ads.ADActivity"
 android :configChanges= "keyboard|keyboardHidden|orientation|screenSize" >
 </ activity >
                

This configuration work is completed

Three: the realization of the function

You can compile a container for advertising by yourself, because this is a blog and not a specific project, so now I will directly create a new page to implement banner advertising 

Let's create a banner advertisement activity first. In the activity package, create a new activity named BannerActivity layout file name.

For activity_banner.xml and then modify the code in the xml as shown below

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />


                
</LinearLayout>  


后面开始写BannerActivity.java里面的代码,如下所示

    import com.qq.e.ads.banner.ADSize;
        import com.qq.e.ads.banner.AbstractBannerADListener;
        import com.qq.e.ads.banner.BannerView;
        import android.app.Activity;
        import android.content.Context;
        import android.os.Bundle;
        import android.widget.RelativeLayout;

//插屏广告的使用  
public class SecondActivity extends Activity {
    private RelativeLayout relcp;// 横幅广告的容器  

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        initView();

    }

    private void initView() {
        relcp = (RelativeLayout) findViewById(R.id.relate);
        TBanner(this, relcp);
    }

    // 加载腾讯横幅广告  
    public static void TBanner(Context context, final RelativeLayout brContainer) {
        // id和广告位id ||测试 1101152570 9079537218417626401  
        // 注:后期需要修改成正式的id和广告位id  
        BannerView bv = new BannerView((Activity) context, ADSize.BANNER,
                "1101152570", "9079537218417626401");
        bv.setRefresh(20);// 广告轮播时间 按钮默认关闭  
        bv.setADListener(new AbstractBannerADListener() {

            @Override
            public void onNoAD(int arg0) {
                // 广告加载失败  

            }

            @Override
            public void onADReceiv() {
                // 加载广告成功时  

            }

            @Override
            public void onADClicked() {
                // 广告点击时  
                super.onADClicked();

            }

        });
        brContainer.addView(bv);
        bv.loadAD();

    }

}  

主要要将里面的数字改成自己的adId和appId

以上便是Android腾讯的banner广告






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325774314&siteId=291194637