SDKv1.0.0接入文档

ADV_SDK v1.0.0

目前只支持AndroidStudio环境接入。接入步骤及示例:
接入前请前往SDK后台申请媒体位,创建代码位后开始接入SDK。

一、环境准备

1、Gradle编译环境minSdkVersion版本需 >= 19
2、复制adv_sdk-1.0.0.aar和msa_mdid_1.0.13.aar文件至主项目中的libs目录下

adv_sdk-1.0.0.aar:激励视频SDK
msa_mdid_1.0.13.aar:安全联盟SDK,用于获取Android10设备标识。

3、在主模块中的build.gradle文件中的android节点下添加如下代码以对aar的支持:
android{
repositories {
        flatDir {
            dirs 'libs'
        }
    }
}
4、为了顺利download第三方库至本地,请在您项目根目录下的build.gradle文件中allprojects节点下添加如下代码:
allprojects {
    repositories {
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}
5、项目中的图片、网络、文件下载等均使用了第三方组件,请在主模块中的build.gradle文件中的dependencies节点下添加如下代码:
dependencies {
   implementation 'com.liulishuo.filedownloader:library:1.7.7'
   implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.18'
   implementation ('com.github.bumptech.glide:glide:4.9.0') {
       exclude group: 'com.android.support'
   }
   implementation(name: 'adv_sdk-1.0.0', ext: 'aar')
   implementation(name: 'msa_mdid_1.0.13', ext: 'aar')
}

二、初始化

请尽可能早的在Application中初始化

        AdvSskConfig config = new AdvSskConfig.Builder()
                .setAccessKey("ebc1928079757cd79b1f2081a172fdf4")//后台商户AccessKey
                .setAppId("100000")//应用媒体APP_ID
                .setAppName("乐乐赚")//应用媒体昵称
                .setNotice(true)//是否开启下载通知栏
                .setDebug(BuildConfig.DEBUG)//是否开启日志输出
                .build();
        //SDK初始化
        LSAdSdk.initSdk(this,config);

三、广告获取

        //构建请求广告所需的配置
        AdMedia adMedia = new AdMedia.Builder()
                .setCodeid("10000000")//广告位
                .setAdCount(1)//预期请求的广告数量,实际返回可能与预期不一致
                .setRewardName("看视频奖金币")//激励名称
                .setRewardAmount(200)//激励数量
                .build();
        LSAdSdk.getAdManager().createAdNative().loadRewardVideoAd(adMedia, new LSAdNative.LSRewardVideoAdListener() {

            @Override
            public void onNativeRewardVideoAd(List nativeAds) {
                if(null!=nativeAds&&nativeAds.size()>0){
                    //这里仅仅只那第一个广告实体做示例
                    mRewardNativeAd = nativeAds.get(0);
                    //注册状态监听
                    mRewardNativeAd.setRewardAdActionListener(new LSRewardNativeAd.AdRewardAdActionListener() {

                        @Override
                        public void onAdShow() {
                            Log.d(TAG,"onAdShow");
                        }

                        @Override
                        public void onAdClick() {
                            Log.d(TAG,"onAdClick");
                        }

                        @Override
                        public void onAdClose() {
                            if(null!=mRewardNativeAd){
                                ///调用destroy后,setDownloadListener已设置的下载监听将失效
                                mRewardNativeAd.destroy();
                                mRewardNativeAd=null;
                            }
                            Log.d(TAG,"onAdClose");
                        }

                        @Override
                        public void onVideoComplete() {
                            Log.d(TAG,"onVideoComplete");
                        }

                        @Override
                        public void onVideoError() {
                            if(null!=mRewardNativeAd){
                                ///调用destroy后,setDownloadListener已设置的下载监听将失效
                                mRewardNativeAd.destroy();
                                mRewardNativeAd=null;
                            }
                            Log.d(TAG,"onVideoError");
                        }

                        @Override
                        public void onRewardVerify(boolean rewardVerify, int rewardAmount, String rewardName) {
                            Log.d(TAG,"onRewardVerify:rewardVerify:"+rewardVerify+",rewardAmount:"+rewardAmount+",rewardName:"+rewardName);
                        }

                        /**
                         * 激励视频暂不支持跳过
                         */
                        @Override
                        public void onSkippedVideo() {
                            Log.d(TAG,"onSkippedVideo");
                        }
                    });
                    //注册下载监听
                    mRewardNativeAd.setDownloadListener(new AdDownloadListener() {

                        @Override
                        public void onConnection(String urlPath) {
                            Log.d(TAG,"onConnection-->");
                        }

                        @Override
                        public void onStart(String urlPath, int soFarBytes, int totalBytes) {
                            Log.d(TAG,"onStart-->urlPath:"+urlPath);
                        }

                        @Override
                        public void onProgress(String urlPath, int soFarBytes, int totalBytes) {
                            Log.d(TAG,"onProgress-->urlPath:"+urlPath);
                        }

                        @Override
                        public void onPause(String urlPath) {
                            Log.d(TAG,"onPause-->urlPath:"+urlPath);
                        }

                        @Override
                        public void onSuccess(String urlPath,File file) {
                            Log.d(TAG,"onSuccess-->file:"+file.getAbsolutePath()+",urlPath:"+urlPath);
                        }

                        @Override
                        public void onError(String urlPath,int code, String msg) {
                            Log.d(TAG,"onError-->code:"+code+",msg:"+msg+",urlPath:"+urlPath);
                        }
                    });

                }

            }

            @Override
            public void onError(int code, String message) {
                Log.d(TAG,"onError-->code:"+code+",message:"+message);
            }
        });

四、广告显示

        mRewardNativeAd.showRewardVideoAd(MainActivity.this);

五、代码混淆

如果您的项目代码开启了混淆功能,请在proguard-rules.pro文件中添加如下代码:

-keep class com.lsaction.opensdk.adv.entity.** {*;}
-keep class com.bun.miitmdid.core.** {*;}

你可能感兴趣的:(SDKv1.0.0接入文档)