deltaDNA智能广告SDK用于将你的Android游戏接入我们的智能广告中间平台。它同时支持空闲广告和奖励广告。
deltaDNA智能广告SDK可以用于基于第16版和更新版本(Android 4.1+)内核SDK的Android项目。
在你的顶层构建脚本
allprojects {
repositories {
maven { url 'http://deltadna.bintray.com/android' }
// 存储你的其他依赖...
}
}在你APP的构建脚本
compile 'com.deltadna.android:deltadna-sdk:VERSION'
compile 'com.deltadna.android:deltadna-smartads:1.10.0'
// 广告提供商
compile 'com.deltadna.android:deltadna-smartads-provider-adcolony:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-admob:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-amazon:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-applovin:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-chartboost:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-facebook:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-flurry:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-hyprmx:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-inmobi:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-ironsource:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-loopme:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-mobfox:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-mopub:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-tapjoy:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-thirdpresence:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-unity:1.10.0'
compile 'com.deltadna.android:deltadna-smartads-provider-vungle:1.10.0'上述广告提供商的任何组合都可以在你的构建脚本中定义,这取决于你想在你的应用程序中使用哪个广告网络。
请注意智能广告使用的版本应当与提供商的版本相同。我们不能保证如果版本不匹配时一个广告提供商可以正常工作。
一个实例可以通过调用DDNASmartAds.instance()函数被取回,同时标记广告可以通过registerForAds(Activity)方法实现。这个分析SDK需要在标记广告前初始化和启用。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DDNA.instance().startSdk();
DDNASmartAds.instance().registerForAds(this);
}当你的Activity被重写、暂停和销毁时,智能广告需要通过优先于生命周期的方法和调用DDNASmartAds中的合适方法被告知。
@Override
public void onResume() {
super.onResume();
DDNASmartAds.instance().onResume();
}
@Override
public void onPause() {
super.onPause();
DDNASmartAds.instance().onPause();
}
@Override
public void onDestroy() {
DDNASmartAds.instance().onDestroy();
DDNA.instance().stopSdk();
super.onDestroy();
}可以通过使用setAdRegistrationListener(AdRegistrationListener)方法来监听空闲广告和奖励广告的注册状态。
DDNASmartAds.instance().setAdRegistrationListener(new AdRegistrationListener() {
// 回调方法
});可以通过创建一个InterstitialAd的实例并调用show()来显示空闲广告。在create()被调用后,结果应当进行null检查,因为如果超过了时间或会话限制后创建可能会失败。
InterstitialAd ad = InterstitialAd.create();
if (ad != null) {
ad.show();
}奖励广告的创建方式也相似,但是要通过RewardedAd类创建。
广告也可以通过执行一个吸引(Engage)请求并创建一个来自返回的Engagement的InterstitialAd或RewardedAd实例被创建。
DDNA.instance().requestEngagement(
new Engagement("myDecisionPoint"),
new EngageListener<Engagement>() {
@Override
public void onCompleted(Engagement engagement) {
RewardedAd reward = RewardedAd.create(engagement);
ImageMessage image = ImageMessage.create(engagement);
if (image != null) {
// 用于显示图像消息的代码
} else if (reward != null) {
reward.show();
}
}
@Override
public void onError(Throwable t) {
// 获取错误
}
}
);这两个类都允许一个监听者在创建监听广告生命周期事件时进入。
这个库在其清单文件中包括所有要求的权限,这个清单文件可以在编译过程中被合并并包含在Android的清单中。这些包含的权限是确保广告提供商功能的最基本要求。所有的这些权限都不是危险权限,因此在Android 6以后的版本都不需要明确的授权。
其他(往往是危险的)权限可能被添加以提高广告网络提供商的功能和性能。这些权限在每一个提供商的清单文件中以注释列出。你可以根据需求添加其中的任一一些到你的应用程序清单中。
如果你为你的应用设置minifyEnabled true,那么没有必要在你的ProGuard配置中添加额外的代码。因为这个库提供了其自己的配置文件,可以在编译过程中被Android编译工具包含进去。
-
当我的项目编译时,我在
transformClassesWithDexForDebug任务中得到了一个TransformException警示。如果你引入了太多的广告提供商导致你的应用包括超过65K的方法时这种情况可能发生。广告提供商可以被移除以减小方法的数量,或者使用一个官方解决方案。
可以从这里找到。
该资源适用于Apache 2.0授权。
