Banner广告集成说明
横幅(Banner)
1. 确定AdHubSDK的主SDK文件已经拷贝到工程文件的libs子目录下参考
2. 在需要添加Banner广告的Activity对应的布局文件中加入一个AdView[com.hubcloud.adhubsdk.AdView]控件来给样式定位
例如:
<!-- view for AdHub Banner Ad --> <com.hubcloud.adhubsdk.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" ads:adUnitId="@string/banner_ad_unit_id" />
注意:wrap_content 不可改为 match_parent
3. 添加广告代码,添加广告代码前请确定已初始化SDK
- 例如:
final AdView adView = (AdView) findViewById(R.id.adView);
adView.setAdUnitId(adUnitId);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("lance", "onAdLoaded");
}
@Override
public void onAdShown() {
Log.i("lance", "onAdShown");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.i("lance", "onAdFailedToLoad");
}
@Override
public void onAdLeftApplication() {
Log.i("lance", "onAdLeftApplication");
}
@Override
public void onAdClosed() {
Log.i("lance", "onAdClosed");
}
@Override
public void onAdOpened() {
Log.i("lance", "onAdOpened");
}
@Override
public void onAdClicked() {
Log.i("lance", "onAdClicked");
}
});
final AdRequest adRequest = new AdRequest.Builder().build();
//建议使用此方法调用loadAd方法
adView.post(new Runnable() {
@Override
public void run() {
adView.loadAd(adRequest);
}
});
PS:更多设置请参考Demo中的com.hubcloud.adhubsdkdemo.BannerActivity的代码.