廣點通文檔
不知道註冊成功以後是否是有更詳細的文檔,暫未知, 我本身註冊的還未經過
找到的教程
這個有點過期, 裏面一些用法跟我如今的不同, 不過很詳細android
個人jar包版本爲GDTUnionSDK.4.18.569.min.jar, 應該是註冊後從官網下載的bash
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
複製代碼
<activity
android:name="com.qq.e.ads.ADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />
<service
android:name="com.qq.e.comm.DownloadService"
android:exported="false" />
複製代碼
咱們以前的老項目沒有加這兩個, 可是廣告正常顯示, 遷移到新項目後沒法顯示, 加上這兩個就正常了app
MultiProcessFlag.setMultiProcess(true)
複製代碼
這個我也不知道幹嗎的ide
new SplashAD(options.mActivity, options.mViewGroup, options.mView, options.mAppId, options.mAdId,
new SplashADListener() {
@Override
public void onADDismissed() {
listener.onADDismissed();
}
@Override
public void onNoAD(AdError error) {
listener.onNoAD(new AdError(error.getErrorCode(), "GDT"+error.getErrorMsg()));
}
@Override
public void onADPresent() {
listener.onADPresent();
}
@Override
public void onADClicked() {
LogUtil.e("onADClicked");
}
@Override
public void onADTick(long l) {
listener.onADTick(l);
}
@Override
public void onADExposure() {
listener.onADExposure();
}
}, options.mShowTime);
複製代碼
private NativeExpressAD mAd;
private NativeExpressADView mAdView;
mAd = new NativeExpressAD(options.mActivity, new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT),
options.mAppId, options.mAdId, new NativeExpressAD.NativeExpressADListener() {
@Override
public void onNoAD(AdError error) {
listener.onNoAD(new com.qmsh.adlibrary.common.AdError(error.getErrorCode(), error.getErrorMsg()));
}
@Override
public void onADLoaded(List<NativeExpressADView> list) {
LogUtil.e("onADLoaded");
if (list == null || list.size() <= 0) {
listener.onNoAD(new com.qmsh.adlibrary.common.AdError(0, "沒返回廣告"));
return;
}
if (mAdView != null) {
mAdView.destroy();
}
mAdView = list.get(0);
// 廣告可見纔會產生曝光,不然將沒法產生收益。
options.mViewGroup.removeAllViews();
options.mViewGroup.addView(mAdView);
mAdView.render();
}
@Override
public void onRenderFail(NativeExpressADView nativeExpressADView) {
LogUtil.e("onRenderFail");
}
@Override
public void onRenderSuccess(NativeExpressADView nativeExpressADView) {
LogUtil.e("onRenderSuccess");
}
@Override
public void onADExposure(NativeExpressADView nativeExpressADView) {
listener.onADExposure();
}
@Override
public void onADClicked(NativeExpressADView nativeExpressADView) {
LogUtil.e("onADClicked");
}
@Override
public void onADClosed(NativeExpressADView nativeExpressADView) {
LogUtil.e("onADClosed");
if (mAd != null) {
mAd.loadAD(1);
}
}
@Override
public void onADLeftApplication(NativeExpressADView nativeExpressADView) {
LogUtil.e("onADLeftApplication");
}
@Override
public void onADOpenOverlay(NativeExpressADView nativeExpressADView) {
LogUtil.e("onADOpenOverlay");
}
@Override
public void onADCloseOverlay(NativeExpressADView nativeExpressADView) {
LogUtil.e("onADCloseOverlay");
}
});
// 注意:若是您在聯盟平臺上新建原生模板廣告位時,選擇了「是」支持視頻,那麼能夠進行個性化設置(可選)
if (options.isVideo) //是不是視頻由後臺返回
mAd.setVideoOption(new VideoOption.Builder()
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI)//WIFI環境下能夠自動播放視頻
.setAutoPlayMuted(true) // 自動播放時爲靜音
.build());
mAd.loadAD(1); //一次拉取的廣告條數:範圍1-30
複製代碼
這個是咱們本身建立的類, 方便封裝廣告參數佈局
public class AdLoadOptions {
@NonNull
public Activity mActivity;
@NonNull
public String mAppId;//應用id
@NonNull
public String mAdId;//廣告id
@NonNull
public ViewGroup mViewGroup;//裝載廣告的容器
public int mShowTime = 5000;//顯示時間(默認5s)
public boolean isVideo;//是不是視頻廣告
public View mView; //騰訊廣告用
public Class mTargetClazz;//瑞獅開屏須要用到廣告
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View"/>
<variable
name="onClick"
type="android.view.View.OnClickListener" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/lyt_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<ImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<FrameLayout
android:id="@+id/adv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/logo" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/logo"
android:onClick="@{onClick}"
android:scaleType="centerCrop" />
<ezy.ui.view.RoundButton
android:id="@+id/btn_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="26dp"
android:layout_marginRight="20dp"
android:onClick="@{onClick}"
android:paddingBottom="2dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="2dp"
android:text="跳過"
android:textColor="#FF666666"
android:textSize="@dimen/text_size_normal"
app:btnCornerRadius="12dp"
app:btnSolidColor="#fff"
app:btnStrokeColor="#FFBEBEBE"
app:btnStrokeWidth="1dp" />
</RelativeLayout>
</FrameLayout>
</layout>
複製代碼