Skip to content

Android聚合广告接入配置

WARNING

U8聚合广告(Velox)是一套广告SDK接入工具,提供了统一的广告API供游戏层快速接入各个广告平台的API。 但U8聚合广告本身并不具备ADX、SSP,DSP等功能。

添加依赖和参数

1、添加依赖jar包

将 u8-ad-demo/libs下面所有jar/aar包放到游戏接入工程中的libs目录下;如果是用androidstudio,请在build.gradle文件中,增加这里所有jar/aar包的依赖。

implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])

2、添加配置文件

将 u8-ad-demo/src/main/assets目录下的所有文件(包括u8_developer_config.properties和u8_plugin_config.xml等文件),拷贝到游戏工程的assets目录下。

按说明修改u8_developer_config.properties中的参数。 如果你不知道如何获取这些参数,请参考文档: 获取参数

U8_APPID: U8SDK后台管理-》游戏管理中创建游戏之后,生成的AppID参数
U8_APPKEY:U8SDK后台管理-》游戏管理中创建游戏之后,生成的AppKey参数
U8_Channel:U8SDK管理后台-》渠道管理中创建渠道(母包测试渠道,渠道商选择【U8测试平台】)之后,生成的渠道号参数

配置Application

游戏层自定义一个Application, 继承com.u8.sdk.U8Application类, 然后在Application对应接口中,调用广告相关的接口:

java
public class AdDemoApplication extends U8Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Velox.getInstance().onAppCreate(this);
    }

    public void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        Velox.getInstance().onAppAttachBaseContext(this, base);
    }

    public void onConfigurationChanged(Configuration config) {
        super.onConfigurationChanged(config);
        Velox.getInstance().onAppConfigurationChanged(this, config);
    }

    public void onTerminate() {
        super.onTerminate();
        Velox.getInstance().onAppTerminate(this);
    }
}

然后在AndroidManifest.xml的application节点中,配置自定义的Application:

xml
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:name="com.velox.ad.demo.AdDemoApplication"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</application>

如果游戏Application已经继承了别的Application类, 可以参考U8聚合SDK->Android接入配置中关于Application部分的说明,进行处理。

生命周期函数

游戏需要在主Activity的生命周期函数中, 调用U8聚合广告的生命周期函数:

点击查看代码
java
public void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    Velox.getInstance().onActivityResult(this, requestCode, resultCode, data);
}

public void onStart(){
    super.onStart();
    Velox.getInstance().onStart(this);
}

public void onPause(){

    super.onPause();
    Velox.getInstance().onPause(this);
}
public void onResume(){
    super.onResume();
    Velox.getInstance().onResume(this);

}
public void onNewIntent(Intent newIntent){
    super.onNewIntent(newIntent);
    Velox.getInstance().onNewIntent(this, newIntent);
}
public void onStop(){
    super.onStop();
    Velox.getInstance().onStop(this);  
}
public void onDestroy(){
    super.onDestroy();
    Velox.getInstance().onDestroy(this);
}
public void onRestart(){
    super.onRestart();  
    Velox.getInstance().onRestart(this);
}

public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    Velox.getInstance().onConfigurationChanged(this, newConfig);
}

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
    
    Velox.getInstance().onRequestPermissionResult(this, requestCode, permissions, grantResults);
}

配置混淆

请在混淆规则中增加如下规则:

bash
-keep class com.velox.** { *; }

开启详细日志

如果在运行时,要开启广告的详细日志,可以在AndroidManifest.xml的application节点内,添加如下配置:

xml
<meta-data android:name="vlog.enable" android:value="true" />
<meta-data android:name="vlog.level" android:value="debug" />
<meta-data android:name="vlog.local" android:value="true" />

版权所有© 2021-2030 上海丞诺网络科技有限公司