广点通sdk接入 _开屏广告

广点通sdk接入 _开屏广告

1:导入架包android-query-full.0.26.7.jar,GDTUnionSDK.4.8.513.jar
2:配置权限等相关操作:
"android.permission.INTERNET" />
    "android.permission.ACCESS_NETWORK_STATE" />
    "android.permission.ACCESS_WIFI_STATE" />
    "android.permission.READ_PHONE_STATE" />
    "android.permission.ACCESS_COARSE_LOCATION" />
    "android.permission.ACCESS_COARSE_UPDATES" />
    "android.permission.WRITE_EXTERNAL_STORAGE" />

    "com.qq.e.comm.DownloadService"
android:exported="false" />

    "com.qq.e.ads.ADActivity"            android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />

3:kaiping.xml布局:
"http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/splash_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.qq.e.union.demo.SplashActivity" >

    "280dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/zp_bg" />



4:详见Activity:
public class KaiPingAd extends Activity implements SplashADListener {
    @SuppressWarnings("unused")
    private SplashAD splashAD;
    private ViewGroup container;// 广告容器

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kaiping);
        container = (ViewGroup) this.findViewById(R.id.splash_container);
        // 构造函数,调用后开屏广告会尝试加载广告,并将广告内容填充到container参数指向的容器,容器中原有的内容会被清空。广告相关状态会通过adListener回传给开发者APP
        splashAD = new SplashAD(this, container, Constants.APPID,
                Constants.SplashPosID, this);
    }

    @Override
    public void onADPresent() {
        // 广告成功展示时调用,成功展示不等于满足计费条件(如展示时长尚未满足)
        Log.e("AD_DEMO", "SplashADPresent");
    }

    @Override
    public void onADDismissed() {
        // 广告关闭时调用,可能是用户关闭或者展示时间到。此时一般需要跳过开屏的Activity,进入应用内容页面
        Log.e("AD_DEMO", "SplashADDismissed");
        next();
    }

    @Override
    public void onNoAD(int arg0) {
        // 广告加载失败,errCode用于描述失败原因。参考文档中ErrorCode相关章节
        Log.e("AD_DEMO", "LoadSplashADFail,ecode=" + arg0);
        next();
    }

    private void next() {
        this.startActivity(new Intent(this, MainPage.class));
        // 防止用户回退看到此页面
        this.finish();
    }

    // 防止用户返回键退出APP
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                || keyCode == KeyEvent.KEYCODE_HOME) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

5:效果图:

广点通sdk接入 _开屏广告_第1张图片

你可能感兴趣的:(第三方sdk接入,Android)