Mopub

关注

通过mopub聚合AdTiming (仅支持原生、插屏和激励视频) 

1. 在Mopub平台添加您的新应用,并设置插屏或激励视频广告位
 
2. 通过菜单Networks → Custom Network → 选择集成类型为SDK Network
 

mopub_adapter_cn_1.png


mopub_adapter_cn_2.png

mopub_adapter_cn_3.png

3. Custom Network设置

■ Custom Event class: 必填项. 此处填入Mopub Adapter的实现类类名。

• Interstitial插屏实现类: com.mopub.mobileads.AdtInterstitial
• Video激励视频实现类: com.mopub.mobileads.AdtVideo
• Native原生广告实现类: com.mopub.nativeads.AdtNative
■ Custom Event class Data:必填项. 此处填传递给Adapter的参数

• JSON-formatted String: {"app_key":"","placement_id":""}

4. 设置Segments, 打开 Segments开关(默认是关闭的)

mopub_adapter_cn_4.png

5. 请参考Mopub 官方文档: official website → The section of Interstitial and Rewarded Video
 
6. Mopub Adapter(原生广告)的调用: 请参考Mopub 原生调用:
<?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="wrap_content">

<ImageView android:id="@+id/privacy_information_icon_image"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
/>

<!—Ads Title Optional -->
<TextView android:id="@+id/native_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="title"
android:layout_below="@+id/privacy_information_icon_image"
/>

<—Ads icon Optional -->
<com.aiming.mdt.nativead.AdIconView
android:id="@+id/iconMediaView"
android:layout_width="250dp"
android:layout_height="175dp"
android:layout_below="@+id/native_ad_title"
android:layout_centerHorizontal="true">

  <ImageView android:id="@+id/native_ad_icon_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</com.aiming.mdt.nativead.AdIconView>

<!—Ads content Optional -->
<TextView android:id="@+id/native_ad_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iconMediaView"
android:layout_centerHorizontal="true"
android:text="text"
/>

<!—Large Graph for Ads Optional -->
<com.aiming.mdt.nativead.MediaView
android:id="@+id/mediaView"
android:layout_width="250dp"
android:layout_height="175dp"
android:layout_below="@+id/native_ad_text"
android:layout_centerHorizontal="true" >
<ImageView android:id="@+id/native_ad_main_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</com.aiming.mdt.nativead.MediaView>
<!—Button for Ads Optional -->
<Button
android:id="@+id/ad_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="btn"
android:textAllCaps="false"
android:layout_below="@+id/mediaView"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>

 import com.mopub.nativeads.AdtMoPubStaticNativeAdRenderer;
 import com.mopub.nativeads.AdtViewBinder;
 import com.mopub.nativeads.MoPubNative;
 import com.mopub.nativeads.NativeAd;
 import com.mopub.nativeads.NativeErrorCode;
 private MoPubNative moPubNative;
 private RelativeLayout adParent;
  //Load the ad
 public void loadNativeAd(View view) {  
     adParent.removeAllViews();
     mNativeAd = null;
     AdtViewBinder viewBinder = new AdtViewBinder.Builder(R.layout.mopub_native_ad_layout)
        .privacyInformationIconImageId(R.id.privacy_information_icon_image)
        .titleId(R.id.native_ad_title)
        .textId(R.id.native_ad_text)
        .iconImageId(R.id.native_ad_icon_image)
        .mainImageId(R.id.native_ad_main_image)
        .callToActionId(R.id.ad_btn)
        .mediaViewId(R.id.mediaView)
        .adIconViewID(R.id.iconMediaView)
        .build();

    moPubStaticNativeAdRenderer = new AdtMoPubStaticNativeAdRenderer(viewBinder, this);
    // The parent container for native ads must be set
    moPubStaticNativeAdRenderer.setAdParent(adParent);
    moPubNative = new MoPubNative(this, adUnitId, this);
    moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
    moPubNative.makeRequest();
 }

 //Show the ad
 public void showNativeAd(View view) {
    if (mNativeAd == null) {
        return;
    }

    View adView = moPubStaticNativeAdRenderer.createAdView(this, null);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
           RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(Gravity.CENTER);
    adParent.removeAllViews();
    adParent.addView(adView, layoutParams);
    mNativeAd.prepare(adView);
    mNativeAd.renderAdView(adView);
  }

  //Successful callback of native ad loading of Mopub
  @Override
  public void onNativeLoad(NativeAd nativeAd) {

      mNativeAd = nativeAd;
      nativeAd.setMoPubNativeEventListener(new NativeAd.MoPubNativeEventListener() {
             @Override
             public void onImpression(View view) {
                Log.d(TAG, "---onImpression--");
             }

             @Override
             public void onClick(View view) {
                Log.d(TAG, "---onClick--");
             }
       });
   }

   //Failure callback of native ad loading of Mopub
   @Override
   public void onNativeFail(NativeErrorCode errorCode) {
      Log.d(TAG, "---onNativeFail--" + errorCode.toString());
   }

 

这篇文章有帮助吗?
0 人中有 0 人觉得有帮助

评论

0 条评论

登录写评论。