Skip to content
ddt8086 edited this page Sep 25, 2019 · 3 revisions

产品介绍:

推啊SDK产品介绍

推啊Android SDK——接入说明文档

[TOC]

1.SDK接入

1.1 媒体后台申请应用的appKey和appSecret

1.2 SDK包导入

1.2.1 项目的build.gradle文件中添加

buildscript {
    repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url "https://dl.bintray.com/sunjiangrong/maven" }
}
    
dependencies {
    classpath 'com.android.tools.build:gradle:3.4.2'
    }
}

allprojects {
        repositories {
            google()
            jcenter()
            maven { url "https://jitpack.io" }
            maven { url "https://dl.bintray.com/sunjiangrong/maven" }
        }
}

1.2.2 app下的build.gradle添加:(最小支持minSdkVersion 15)

dependencies {
    implementation ('com.tuia:sdk:1.0.0.0'){
    	transitive = true
	}
}

1.3 AndroidManifest配置

1.3.1.权限

//(sdk内部已经处理相关权限问题,如果遇到冲突咨询对应开发即可)
<uses-permission android:name="android.permission.INTERNET"/>

1.3.2.设置meta-data(推啊appkey和appSecret从媒体管理后台获取 咨询运营人员)

    <!-- 推啊appkey-->
    <meta-data
        android:name="TUIA_APPKEY"
        android:value="kEzAJT4iRMMag29Z7yWcJGfcVgG" />
    <!-- 推啊appSecret -->
    <meta-data
        android:name="TUIA_APPSECRET"
        android:value="3Wq4afvvdPhyHBR29LgRwEC16gkrrFXZ5BRoL2E" />

1.4 运行环境配置

本SDK可运行于Android4.1 (API Level 15) 及以上版本。

<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="28" />

1.5 混淆

-ignorewarnings
-dontwarn com.lechuan.midunovel.view.**
-keep class com.lechuan.midunovel.view.** { *; }

1.6 初始化SDK

1.6.1.初始化

在自定义的Application 的onCreate方法中,调用以下方法:(详细内容请参考demo中的代码示例)

FoxSDK.init(this);

2.加载广告

2.1 选择合适的广告类型

2.1.1 开屏广告接入

(开屏广告嵌入代码说明(详见demo代码))

第一步:xml中引入布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/default_image_background">

    <com.lechuan.midunovel.view.FoxShView
        android:id="@+id/TMSh_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:countTime="2" />

</RelativeLayout>

第二步:代码引入示例

public class SplashActivity extends Activity {

protected FoxShView mOXShView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    //获取开屏广告对象
    mOXShView = (FoxShView)findViewById(R.id.TMSh_container);
    //设置跳转目标
    mOXShView.setTargetClass(this,MainActivity.class);
    //设置广告监听
    mOXShView.setAdListener(new FoxShListener(){
        @Override
        public void onTimeOut() {
            Log.d("TMShActivity", "onTimeOut");
        }

        @Override
        public void onReceiveAd() {
            Log.d("TMShActivity", "onReceiveAd");
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("TMShActivity", "onFailedToReceiveAd");
        }

        @Override
        public void onLoadFailed() {
            Log.d("TMShActivity", "onLoadFailed");
        }

        @Override
        public void onCloseClick() {
            Log.d("TMShActivity", "onCloseClick");
        }

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

        @Override
        public void onAdExposure() {
            Log.d("TMShActivity", "onAdExposure");
        }
        
        @Override
        public void onAdReward(String data) {
            Log.d("========", "onAdReward");
        }
    });
    //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mOXShView.loadAd(466,"userId");
}


    @Override
protected void onDestroy() {
    //销毁控件
    if (mOXShView != null) {
        mOXShView.destroy();
    }
    super.onDestroy();
}

2.1.2横幅广告接入

(横幅广告嵌入代码说明(详见demo代码))

第一步:xml中引入布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.lechuan.midunovel.view.FoxStreamerView
        android:id="@+id/TMBrView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:fox_size="lander_foxBr"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background"/>

</LinearLayout>

第二步:代码引入示例

public class SbannerActivity extends BaseActivity {

private FoxStreamerView mTMBrAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sbanner);
    mTMBrAdView = (FoxStreamerView) findViewById(R.id.TMBrView);
  
    //设置监听
    mTMBrAdView.setAdListener(new FoxListener() {
        @Override
        public void onReceiveAd() {
            Log.d("========", "onReceiveAd");
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("========", "onFailedToReceiveAd");
        }

        @Override
        public void onLoadFailed() {
            Log.d("========", "onLoadFailed");
        }

        @Override
        public void onCloseClick() {
            Log.d("========", "onCloseClick");
        }

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

        @Override
        public void onAdExposure() {
            Log.d("========", "onAdExposure");
        }

        @Override
        public void onAdReward(String data) {
            Log.d("========", "onAdReward");
        }
    });
    //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mTMBrAdView.loadAd(308403,userId);
}

@Override
protected void onDestroy() {
    //销毁控件
    if (mTMBrAdView != null) {
        mTMBrAdView.destroy();
    }
    super.onDestroy();
}

}

2.1.3 浮标广告接入

(浮标广告嵌入代码说明(详见demo代码))

第一步:xml中引入布局文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.lechuan.midunovel.view.FoxWallView
        android:id="@+id/TMAw1"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="center_vertical|right"
        tools:wall_shape="square"/>

</FrameLayout>

第二步:代码引入示例

public class DobberActivity extends BaseActivity {
private ListView mListView;
private FoxWallView mOxWallView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dobber);
    mOxWallView = (FoxWallView) findViewById(R.id.TMAw1);
    //设置广告监听
    mOxWallView.setAdListener(new FoxListener() {
        @Override
        public void onReceiveAd() {
            Log.d("========", "onReceiveAd");
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("========", "onFailedToReceiveAd");
        }

        @Override
        public void onLoadFailed() {
            Log.d("========", "onLoadFailed");
        }

        @Override
        public void onCloseClick() {
            Log.d("========", "onCloseClick");
        }

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

        @Override
        public void onAdExposure() {
            Log.d("========", "onAdExposure");
        }

        @Override
        public void onAdReward(String data) {
            Log.d("========", "onAdReward");
        }
    });
    //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mOxWallView.loadAd(301971,userId);
}

@Override
protected void onDestroy() {
    //销毁控件
    if (mOxWallView != null) {
        mOxWallView.destroy();
    }
    super.onDestroy();
    }
}

2.1.4 插屏广告接入

(插屏广告嵌入代码说明(详见demo代码))

第一步:代码直接引入示例

public class InterstitialActivity extends BaseActivity {
private FoxTbScreen mTMItAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_interstitial);
    //创建广告对象
    mTMItAd = new FoxTbScreen(this);
    //设置广告监听
    mTMItAd.setAdListener(new FoxListener() {
        @Override
        public void onReceiveAd() {
            Log.d("========", "onReceiveAd");
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("========", "onFailedToReceiveAd");
        }

        @Override
        public void onLoadFailed() {
            Log.d("========", "onLoadFailed");
        }

        @Override
        public void onCloseClick() {
            Log.d("========", "onCloseClick");
        }

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

        @Override
        public void onAdExposure() {
            Log.d("========", "onAdExposure");
        }

        @Override
        public void onAdReward(String data) {
            Log.d("========", "onAdReward");
        }
    });
     //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mTMItAd.loadAd(301968,userId);
}
@Override
protected void onDestroy() {
    //销毁控件
    if (mTMItAd != null) {
        mTMItAd.destroy();
    }
    super.onDestroy();
}
}

2.1.5 应用墙广告接入

(应用墙广告嵌入代码说明(详见demo代码))

第一步:xml中引入布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="horizontal">
    
    <com.lechuan.midunovel.view.FoxWallView
        android:id="@+id/app1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:scaleType="centerCrop"
        tools:wall_shape="circular"/>

</LinearLayout>

第二步:代码引入示例

public class AppWallActivity extends BaseActivity {
private FoxWallView mOxWallView1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_app_wall);
    mOxWallView1 = (FoxWallView) findViewById(R.id.app1);
 
    //设置广告监听
    mOxWallView1.setAdListener(new FoxListener() {
        @Override
        public void onReceiveAd() {
            Log.d("========", "onReceiveAd");
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("========", "onFailedToReceiveAd");
        }

        @Override
        public void onLoadFailed() {
            Log.d("========", "onLoadFailed");
        }

        @Override
        public void onCloseClick() {
            Log.d("========", "onCloseClick");
        }

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

        @Override
        public void onAdExposure() {
            Log.d("========", "onAdExposure");
        }

        @Override
        public void onAdReward(String data) {
            Log.d("========", "onAdReward");
        }
    });
    //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mOxWallView2.loadAd(301972,userId);
}

@Override
protected void onDestroy() {
    //销毁控件
    if (mOxWallView1 != null) {
        mOxWallView1.destroy();
    }
    super.onDestroy();
}
}

2.1.6 Banner广告接入

(Banner广告嵌入代码说明(详见demo代码))

第一步:xml中引入布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.lechuan.midunovel.view.FoxStreamerView
        android:id="@+id/TMBrView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:fox_size="foxBr" />

</LinearLayout>

第二步:代码引入示例

public class BannerActivity extends BaseActivity {
private FoxStreamerView mTMBrAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_banner);
    mTMBrAdView = (FoxStreamerView) findViewById(R.id.TMBrView);
    ////设置广告监听
    mTMBrAdView.setAdListener(new FoxListener() {
        @Override
        public void onReceiveAd() {
            Log.d("========", "onReceiveAd");
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("========", "onFailedToReceiveAd");
        }

        @Override
        public void onLoadFailed() {
            Log.d("========", "onLoadFailed");
        }

        @Override
        public void onCloseClick() {
            Log.d("========", "onCloseClick");
        }

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

        @Override
        public void onAdExposure() {
            Log.d("========", "onExposure");
        }

        @Override
        public void onAdReward(String data) {
            Log.d("========", "onAdReward");
        }
    });
     //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mTMBrAdView.loadAd(301970,userId);
}

@Override
protected void onDestroy() {
    //销毁控件
    if (mTMBrAdView != null) {
        mTMBrAdView.destroy();
    }
    super.onDestroy();
    }
}

2.1.7 自定义广告接入

(自定义广告嵌入代码说明(详见demo代码))

注意:自定义广告需要单独调用 广告曝光 和 广告点击 事件

第一步:代码直接引入示例

public class NonStandarActivity extends BaseActivity {
private FoxCustomerTm mOxCustomerTm;

private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_non_standar);
    textView = (TextView)findViewById(R.id.content_text);
   
    //创建广告对象
    mOxCustomerTm = new FoxCustomerTm(this);
     //加载广告,传入对应的(必传)广告位id和(必传)用户id
    mOxCustomerTm.loadAd(304507,userId);

    mOxCustomerTm.setAdListener(new FoxNsTmListener() {
        @Override
        public void onReceiveAd(String result) {
            //获取广告返回结果
            Log.d("========", "onReceiveAd:"+result);
            textView.setText(result);
        }

        @Override
        public void onFailedToReceiveAd() {
            Log.d("========", "onFailedToReceiveAd");
        }

        @Override
        public void onAdReward(String data) {

        }
    });
}


@Override
protected void onDestroy() {
    //销毁控件
    if (mOxCustomerTm != null) {
        mOxCustomerTm.destroy();
    }
    super.onDestroy();
}
}

第二步:广告曝光的时候必须调用

mOxCustomerTm.adExposed();

第三步:广告点击的时候必须调

mOxCustomerTm.adClicked();

2.2 关于返回奖励信息 所有广告类型中的回调 onAdReward(String data)(激励类型广告使用,非激励类型广告不需要)

{
    "finishType" : 1,
    "orderId" : "168408070629",
    "userId" : "123",
    "timestamp" : "1566791113031",
    "prizeFlag" : "XXX",
    "appKey" : "4W8ReCvDm4fy3Fpn52MgPgUWmdfS",
    "sign" : "5093659d6bf802d1a407df81d6aab9f9",
    "score" : null,
    "reason" : "-1",
    "url" : null
} 
名称 类型 备注
userId String 用户 id,用户在媒体的唯一识别信息,来源于活动链接中的&userId=xxx,由媒体拼接提供
timestamp Number 时间戳
prizeFlag String 常量,请求上报的奖励在对接方媒体系统内的奖励标识,用于标识具体的奖励类型,由媒体提供
orderId String 推啊订单号,具有唯一性,幂等由媒体保障
appKey String 媒体公钥
sign String 签名
score Number 如果是数值类型的奖励,则同时请求充值对应的数值 score,比如积分、金币、倍数