문서가 업데이트되었습니다.
한국어로 번역이 아직 완료되지 않았습니다.
영어 업데이트됨: 11월 18일
한국어 업데이트됨: 2022. 6. 3.

Add Interstitial Ads to an Android App

The Audience Network allows you to monetize your Android apps with Facebook ads. An interstitial ad is a full screen ad that you can show in your app. Typically interstitial ads are shown when there is a transition in your app. For example -- after finishing a level in a game or after loading a story in a news app.

계속하기 전에 Audience Network 시작하기Android 시작하기 가이드를 완료했는지 확인하세요.

Steps-by-Step

Step 1: Initializing Interstitial Ads in your Activity

Step 2: Showing Interstitial Ads in your Activity

Audience Network SDK 초기화

이 메서드는 Android Audience Network SDK 버전 5.1에 추가되었습니다.

5.3.0 버전 이상에서는 Audience Network Android SDK의 명시적 초기화가 필수입니다. Audience Network Android SDK를 초기화하는 방법은 이 문서를 참조하세요.

개체를 만들고 광고를 읽어들이기 전에 먼저 Audience Network SDK를 초기화해야 합니다. 이 작업은 앱 실행 시에 하는 것이 좋습니다.

public class YourApplication extends Application {
    ...
    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize the Audience Network SDK
        AudienceNetworkAds.initialize(this);       
    }
    ...
}

Step 1: Initializing Interstitial Ads in your Activity

Add the following code at the top of your Activity in order to import the Facebook Ads SDK:

import com.facebook.ads.*;

Initialize the InterstitialAd.

private InterstitialAd interstitialAd;

@Override
public void onCreate(Bundle savedInstanceState) {
...
  // Instantiate an InterstitialAd object. 
  // NOTE: the placement ID will eventually identify this as your App, you can ignore it for
  // now, while you are testing and replace it later when you have signed up.
  // While you are using this temporary code you will only get test ads and if you release
  // your code like this to the Google Play your users will not receive ads (you will get a no fill error).
  interstitialAd = new InterstitialAd(this, "YOUR_PLACEMENT_ID");
...  

Step 2: Showing Interstitial Ads

Scenario 1: Create an InterstitialAdListener, load the Ad and show the Ad immediately it is loaded successfully.

public class InterstitialAdActivity extends Activity {

    private final String TAG = InterstitialAdActivity.class.getSimpleName();
    private InterstitialAd interstitialAd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Instantiate an InterstitialAd object.
        // NOTE: the placement ID will eventually identify this as your App, you can ignore it for
        // now, while you are testing and replace it later when you have signed up.
        // While you are using this temporary code you will only get test ads and if you release
        // your code like this to the Google Play your users will not receive ads (you will get a no fill error).
        interstitialAd = new InterstitialAd(this, "YOUR_PLACEMENT_ID");
        // Create listeners for the Interstitial Ad
        InterstitialAdListener interstitialAdListener = new InterstitialAdListener() {
            @Override
            public void onInterstitialDisplayed(Ad ad) {
                // Interstitial ad displayed callback
                Log.e(TAG, "Interstitial ad displayed.");
            }

            @Override
            public void onInterstitialDismissed(Ad ad) {
                // Interstitial dismissed callback
                Log.e(TAG, "Interstitial ad dismissed.");
            }

            @Override
            public void onError(Ad ad, AdError adError) {
                // Ad error callback
                Log.e(TAG, "Interstitial ad failed to load: " + adError.getErrorMessage());
            }

            @Override
            public void onAdLoaded(Ad ad) {
                // Interstitial ad is loaded and ready to be displayed
                Log.d(TAG, "Interstitial ad is loaded and ready to be displayed!");
                // Show the ad
                interstitialAd.show();
            }

            @Override
            public void onAdClicked(Ad ad) {
                // Ad clicked callback
                Log.d(TAG, "Interstitial ad clicked!");
            }

            @Override
            public void onLoggingImpression(Ad ad) {
                // Ad impression logged callback
                // Please refer to Monetization Manager or Reporting API for final impression numbers
                Log.d(TAG, "Interstitial ad impression logged!");
            }
        };

        // For auto play video ads, it's recommended to load the ad
        // at least 30 seconds before it is shown
        interstitialAd.loadAd(
                interstitialAd.buildLoadAdConfig()
                        .withAdListener(interstitialAdListener)
                        .build());
    }
}

Interstitial Ads have creatives that are larger in size so a good practice is calling loadAd(...) in advance and then calling show() at the appropriate time.

Scenario 2: Display the ad in a few seconds or minutes after it is successfully loaded. You should check whether the ad has been invalidated before displaying it.

In case of not showing the ad immediately after the ad has been loaded, the developer is responsible for checking whether or not the ad has been invalidated. Once the ad is successfully loaded, the ad will be valid for 60 mins. You will not get paid if you are showing an invalidated ad.

You should follow the idea below, but please do not copy the code into your project since it is just an example:

public class InterstitialAdActivity extends Activity {

    private InterstitialAd  interstitialAd ;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Instantiate an InterstitialAd object. 
        // NOTE: the placement ID will eventually identify this as your App, you can ignore it for
        // now, while you are testing and replace it later when you have signed up.
        // While you are using this temporary code you will only get test ads and if you release
        // your code like this to the Google Play your users will not receive ads (you will get a no fill error).
        interstitialAd = new InterstitialAd(this, "YOUR_PLACEMENT_ID");
        InterstitialAdListener interstitialAdListener = new InterstitialAdListener() {
            ...
        };
        // load the ad
        interstitialAd.loadAd(
                interstitialAd.buildLoadAdConfig()
                        .withAdListener(interstitialAdListener)
                        .build());
    }

    private void showAdWithDelay() {
       /**
        * Here is an example for displaying the ad with delay;
        * Please do not copy the Handler into your project
       */
       // Handler handler = new Handler();
       handler.postDelayed(new Runnable() {
           public void run() {
                // Check if interstitialAd has been loaded successfully
               if(interstitialAd == null || !interstitialAd.isAdLoaded()) {
                   return;
               }
                // Check if ad is already expired or invalidated, and do not show ad if that is the case. You will not get paid to show an invalidated ad.
               if(interstitialAd.isAdInvalidated()) {
                   return;
               }
               // Show the ad
                interstitialAd.show(); 
           }
       }, 1000 * 60 * 15); // Show the ad after 15 minutes
    }
}

Finally, add the following code to your Activity's onDestroy() function to release resources the InterstitialAd uses:

@Override
protected void onDestroy() {
    if (interstitialAd != null) {
        interstitialAd.destroy();
    }
    super.onDestroy();
}

기본 Google Android 에뮬레이터를 사용하는 경우 테스트 광고를 읽어들이기 전에 다음 코드 행을 추가합니다.
AdSettings.addTestDevice("HASHED ID");.

기기에 광고를 읽어들이기를 처음 요청할 때는 logcat에 인쇄되어 있는 해시 처리된 ID를 사용하세요.

Genymotion 및 실제 기기에서는 이 단계가 필요하지 않습니다. 실제 광고를 사용하여 테스트하려면 테스트 가이드를 참조하세요.

Start your app and you should see an Interstitial Ad appear:

동영상 광고를 위한 하드웨어 가속화

Audience Network의 동영상 광고에는 하드웨어 가속화된 렌더링을 활성화해야 하며, 그렇지 않을 경우 동영상 조회 시 검은 화면이 나타날 수 있습니다. 이 제한 사항은 다음 항목에 적용됩니다.

  • 네이티브 광고의 동영상 크리에이티브
  • 삽입 광고의 동영상 크리에이티브
  • 인스트림 동영상 광고
  • 보상형 동영상

타겟 API 수준이 14(Ice Cream Sandwich, Android 4.0.1) 이상이면 하드웨어 가속화가 기본적으로 활성화되지만 앱 수준이나 활동 수준에서 명시적으로 이 기능을 활성화할 수도 있습니다.

앱 수준

앱 전체에 대하여 하드웨어 가속화를 활성화하려면 Android 매니페스트 파일의 <application> 태그에 다음과 같은 속성을 추가하세요.

<application android:hardwareAccelerated="true" ...>

활동 수준

앱에서 특정 활동에 대해서만 기능을 활성화하려면 Android 매니페스트 파일에서 <activity> 태그에 다음 속성을 추가하세요. 다음 예에서는 삽입 광고 및 보상형 동영상 렌더링에 사용되는 AudienceNetworkActivity에 대한 하드웨어 가속화를 활성화합니다.

<activity android:name="com.facebook.ads.AudienceNetworkActivity" android:hardwareAccelerated="true" .../>

Next Steps