「Android InRead Ads」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
imported>Wikiuser
行 52: 行 52:
<br>
<br>
<big><u>Step 2: 廣告初始設置</u></big><br>
<big><u>Step 2: 廣告初始設置</u></big><br>
:您必須輸入<b>廣告大小(TWMAdSize)</b>、<b>InRead版位ID</b>以初始化InRead物件, 並且設置Listener偵聽廣告的Callback
:您必須輸入<b>廣告大小(TWMAdSize)</b>、<b>InRead大圖式版位ID</b>以初始化InRead物件, 並且設置Listener偵聽廣告的Callback
:<b><span style="color:red;">重要! 請務必在onResume、onPause和onDestroy分別加上resume、pause和destroy函式, 避免廣告發生無法預期的問題</span></b>
:<b><span style="color:red;">重要! 請務必在onResume、onPause和onDestroy分別加上resume、pause和destroy函式, 避免廣告發生無法預期的問題</span></b>
   public class MainActivity extends Activity{
   public class MainActivity extends Activity{
行 67: 行 67:
         rectView = new TWMInReadAdRect(MainActivity.this,
         rectView = new TWMInReadAdRect(MainActivity.this,
               TWMAdSize.IN_READ_1200X627, <b>"<TAMedia_InRead_AdUnitId>"</b>);
               TWMAdSize.IN_READ_1200X627, <b>"<TAMedia_InRead_AdUnitId>"</b>);
   
        // Set listener for inread.
        rectView.setAdListener(adListener);
 
        // Add inread into container.
        adContainer.addView(rectView);
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        if (rectView != null) {
            rectView.resume();
        }
    }
   
    @Override
    protected void onPause() {
        if (rectView != null) {
            rectView.pause();
        }   
        super.onPause();
    }
   
    @Override
    protected void onDestroy() {
        if (rectView != null) {
            rectView.destroy();
        } 
        super.onDestroy();
    }
 
    private TWMAdViewListener adListener = new TWMAdViewListener() {
        @Override
        public void onReceiveAd(TWMAd twmAd) {
            // The callback is trigger when ad load successfully.
        }
       
        @Override
        public void onFailedToReceiveAd(TWMAd twmAd, TWMAdRequest.ErrorCode errorCode) {
            // The callback is trigger when ad load fail.
        }
       
        @Override
        public void onPresentScreen(TWMAd twmAd) {
            // The callback is triggered when user has clicked ad.
        }
       
        @Override
        public void onDismissScreen(TWMAd twmAd) {
            // The callback is triggered when user has returned to the app after clicking ad.
        }
 
        @Override
        public void onLeaveApplication(TWMAd twmAd) {
            // The callback would be trigeer when user has left the app.
        }
    };
 
  }
<br>
<big><u>Step 3: 請求廣告</u></big><br>
:在您需要的地方呼叫loadAd以進行廣告請求
  // Request inread from TAMedia.
  if (rectView != null) {
    rectView.loadAd(new TWMAdRequest());
  }
<br><br>
===<b>300 x 250</b> ===
<big><u>Step 1: 設置廣告的XML (以ScrollView為例) </u></big><br>
:此部分設置與大圖式相同, 請參考<b>大圖式 Step 1</b>
<br>
<big><u>Step 2: 廣告初始設置</u></big><br>
:您必須輸入<b>廣告大小(TWMAdSize)</b>、<b>InRead 300x250 版位ID</b>以初始化InRead物件, 並且設置Listener偵聽廣告的Callback
:<b><span style="color:red;">重要! 請務必在onResume、onPause和onDestroy分別加上resume、pause和destroy函式, 避免廣告發生無法預期的問題</span></b>
  public class MainActivity extends Activity{
    private RelativeLayout adContainer = null;
    private TWMInReadAdRect rectView = null;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        adContainer = (RelativeLayout) findViewById(R.id.inread_ad_container);
   
        // Init InRead Object
        rectView = new TWMInReadAdRect(MainActivity.this,
              TWMAdSize.IAB_MRECT, <b>"<TAMedia_InRead_AdUnitId>"</b>);
      
      
         // Set listener for inread.
         // Set listener for inread.

於 2018年6月8日 (五) 06:36 的修訂

簡介

InRead廣告是SDK6新增的內嵌式廣告, 該廣告會在使用者滑動文章、列表時出現, InRead廣告分為下列三種:
  • 大圖式: 夾雜在文章中, 大小為1200x627, 會根據父元件大小縮放(Fit-Width)
  • 300x250: 與大圖式相似, 差別為300x250並不會隨父元件縮放
  • Anchor: 固定在螢幕下方的廣告, 廣告高度不會超過螢幕的30%
在介接方式上, 大圖、300x250與橫幅廣告相似, 而Anchor與懸浮廣告相似, 下列章節將說明如何串接InRead廣告


介接方式

大圖式

Step 1: 設置廣告的XML (以ScrollView為例)

假設InRead廣告被夾在兩個TextView之間
 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_marginLeft="15sp"
     android:layout_marginRight="15sp"
     android:layout_marginTop="50sp">
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical"
         android:descendantFocusability="blocksDescendants"> 
 
         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="This is a long article. Please scroll down to find your inread ad.  ....">
         </TextView>
 
         <RelativeLayout
             android:id="@+id/inread_ad_container"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_horizontal">
         </RelativeLayout>
 
         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="This is a long article. Please scroll up to find your inread ad.  ....">
         </TextView>
 
     </LinearLayout>
 
 </ScrollView> 


Step 2: 廣告初始設置

您必須輸入廣告大小(TWMAdSize)InRead大圖式版位ID以初始化InRead物件, 並且設置Listener偵聽廣告的Callback
重要! 請務必在onResume、onPause和onDestroy分別加上resume、pause和destroy函式, 避免廣告發生無法預期的問題
 public class MainActivity extends Activity{
    private RelativeLayout adContainer = null;
    private TWMInReadAdRect rectView = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       adContainer = (RelativeLayout) findViewById(R.id.inread_ad_container);
    
       // Init InRead Object
       rectView = new TWMInReadAdRect(MainActivity.this,
             TWMAdSize.IN_READ_1200X627, "<TAMedia_InRead_AdUnitId>");
   
       // Set listener for inread.
       rectView.setAdListener(adListener); 
 
       // Add inread into container.
       adContainer.addView(rectView); 
    }
 
    @Override
    protected void onResume() {
       super.onResume();
       if (rectView != null) {
           rectView.resume();
       }
    }
    
    @Override
    protected void onPause() {
       if (rectView != null) {
           rectView.pause();
       }    
       super.onPause();
    }
    
    @Override
    protected void onDestroy() {
       if (rectView != null) {
           rectView.destroy();
       }   
       super.onDestroy();
    }
 
    private TWMAdViewListener adListener = new TWMAdViewListener() {
        @Override
        public void onReceiveAd(TWMAd twmAd) {
            // The callback is trigger when ad load successfully.
        }
        
        @Override
        public void onFailedToReceiveAd(TWMAd twmAd, TWMAdRequest.ErrorCode errorCode) {
            // The callback is trigger when ad load fail.
        }
        
        @Override
        public void onPresentScreen(TWMAd twmAd) {
            // The callback is triggered when user has clicked ad.
        }
        
        @Override
        public void onDismissScreen(TWMAd twmAd) {
            // The callback is triggered when user has returned to the app after clicking ad.
        }
 
        @Override
        public void onLeaveApplication(TWMAd twmAd) {
            // The callback would be trigeer when user has left the app.
        }
    };
 
 }


Step 3: 請求廣告

在您需要的地方呼叫loadAd以進行廣告請求
 // Request inread from TAMedia.
 if (rectView != null) {
    rectView.loadAd(new TWMAdRequest());
 }



300 x 250

Step 1: 設置廣告的XML (以ScrollView為例)

此部分設置與大圖式相同, 請參考大圖式 Step 1


Step 2: 廣告初始設置

您必須輸入廣告大小(TWMAdSize)InRead 300x250 版位ID以初始化InRead物件, 並且設置Listener偵聽廣告的Callback
重要! 請務必在onResume、onPause和onDestroy分別加上resume、pause和destroy函式, 避免廣告發生無法預期的問題
 public class MainActivity extends Activity{
    private RelativeLayout adContainer = null;
    private TWMInReadAdRect rectView = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       adContainer = (RelativeLayout) findViewById(R.id.inread_ad_container);
    
       // Init InRead Object
       rectView = new TWMInReadAdRect(MainActivity.this,
             TWMAdSize.IAB_MRECT, "<TAMedia_InRead_AdUnitId>");
   
       // Set listener for inread.
       rectView.setAdListener(adListener); 
 
       // Add inread into container.
       adContainer.addView(rectView); 
    }
 
    @Override
    protected void onResume() {
       super.onResume();
       if (rectView != null) {
           rectView.resume();
       }
    }
    
    @Override
    protected void onPause() {
       if (rectView != null) {
           rectView.pause();
       }    
       super.onPause();
    }
    
    @Override
    protected void onDestroy() {
       if (rectView != null) {
           rectView.destroy();
       }   
       super.onDestroy();
    }
 
    private TWMAdViewListener adListener = new TWMAdViewListener() {
        @Override
        public void onReceiveAd(TWMAd twmAd) {
            // The callback is trigger when ad load successfully.
        }
        
        @Override
        public void onFailedToReceiveAd(TWMAd twmAd, TWMAdRequest.ErrorCode errorCode) {
            // The callback is trigger when ad load fail.
        }
        
        @Override
        public void onPresentScreen(TWMAd twmAd) {
            // The callback is triggered when user has clicked ad.
        }
        
        @Override
        public void onDismissScreen(TWMAd twmAd) {
            // The callback is triggered when user has returned to the app after clicking ad.
        }
 
        @Override
        public void onLeaveApplication(TWMAd twmAd) {
            // The callback would be trigeer when user has left the app.
        }
    };
 
 }


Step 3: 請求廣告

在您需要的地方呼叫loadAd以進行廣告請求
 // Request inread from TAMedia.
 if (rectView != null) {
    rectView.loadAd(new TWMAdRequest());
 }