バナー - 広告ユニットAPIへの移行 - Android

このガイドでは、現在の実装から LevelPlay バナー API(広告ユニット ID を使用)へ移行し、バナー広告をロード・表示する方法について説明します。

Before you start
  • サポートされる最小SDKは8.6.0です。最新の SDK はこちらからダウンロードできます。
  • LevelPlay 初期化 API を使用してSDKを初期化してください。詳細はこちらをご覧ください。
  • AdUnitID は LevelPlay ダッシュボードで確認できます。詳細はこちら

バナー広告オブジェクトの作成とサイズ設定

バナー広告オブジェクトの作成は、onInitSuccess コールバックを受け取った後に行ってください。

// Create the banner view and set the ad unit id
LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
// Create the banner view and set the ad unit id
val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")

バナーサイズ

レガシー 広告ユニット(New) dp 単位のサイズ
ISBannerSize LevelPlayAdSize (幅 × 高さ)
BANNER BANNER 320 x 50
LARGE LARGE 320 x 90
RECTANGLE MEDIUM_RECTANGLE 300 x 250
SMART Adaptive Ad Size に置き換え(下記参照) モバイルやタブレットの画面サイズ・向きに自動調整される広告

広告サイズの作成方法は以下のいずれかになります:

画面幅に自動対応するアダプティブバナーサイズ(推奨):
このオプションはデバイス種別により BANNER または LEADERBOARD を返します。アダプティブ機能対応ネットワーク(Google, Yandex等)は最適化ロジックにより高さを返します。

LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
val adSize = createAdaptiveAdSize(context)

特定バナーサイズの指定:
この方法ではBANNER、LARGE、MEDIUM_RECTANGLEのサイズを明示的に指定できます。

levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE);
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE)

プレースメント

バナー広告はプレースメントに対応しており、レポート用途で利用可能です。loadAd より前に設定することで、全てのリロード広告に適用されます。

// Set the placement name
levelPlayBanner.setPlacementName("placementName");
// Set the placement name
levelPlayBanner.setPlacementName("placementName")

バナーリスナーの実装

LevelPlayBannerListener の代わりに、LevelPlayBannerAdViewListener を実装してください。

  • バナー広告のロード前にリスナーを設定することを推奨します。
  • 各バナー広告それぞれにリスナー実装が必要です。
  • コールバックはメインスレッドで実行されます。
levelPlayBanner.setBannerListener(new LevelPlayBannerAdViewListener() {
    @Override
    public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {
    // Ad was loaded successfully 
    }
    @Override
    public void onAdLoadFailed(@NonNull LevelPlayAdError error) {
    // Ad load failed
    }
    @Override
    public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {
    // Ad was displayed and visible on screen
    }
    @Override
    public void onAdDisplayFailed(@NonNull LevelPlayAdInfo adInfo, @NonNull LevelPlayAdError error) {
    // Ad failed to be displayed on screen
    }
    @Override
    public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {
    // Ad was clicked
    }
    @Override
    public void onAdExpanded(@NonNull LevelPlayAdInfo adInfo) {
    // Ad is opened on full screen
    }
    @Override
    public void onAdCollapsed(@NonNull LevelPlayAdInfo adInfo) {
    // Ad is restored to its original size
    }
    @Override
    public void onAdLeftApplication(@NonNull LevelPlayAdInfo adInfo) 
    // User pressed on the ad and was navigated out of the app 
    }
});
levelPlayBanner.setBannerListener(object: LevelPlayBannerAdViewListener {
    override fun onAdLoaded(adInfo: LevelPlayAdInfo) {
    // Ad was loaded successfully 
    }
    override fun onAdLoadFailed(error: LevelPlayAdError) {
    // Ad load failed
    }
    override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {
    // Ad was displayed and visible on screen
    }
    override fun onAdDisplayFailed(adInfo: LevelPlayAdInfo, error: LevelPlayAdError) {
    // Ad failed to be displayed on screen
    }
    override fun onAdClicked(adInfo: LevelPlayAdInfo) {
    // Ad was clicked
    }
    override fun onAdExpanded(adInfo: LevelPlayAdInfo) {
    // Ad is opened on full screen
    }
    override fun onAdCollapsed(adInfo: LevelPlayAdInfo) {
    // Ad is restored to its original size
    }
    override fun onAdLeftApplication(adInfo: LevelPlayAdInfo) {
    // User pressed on the ad and was navigated out of the app 
    }
})
レガシー 広告ユニット(New)
Listener LevelPlayBannerListener LevelPlayBannerAdViewListener
Callbacks onAdLoaded onAdLoaded
onAdLoadFailed onAdLoadFailed
onAdClicked onAdClicked
onAdScreenPresented onAdExpanded
onAdScreenDismissed onAdCollapsed
onAdLeftApplication onAdLeftApplication
onAdDisplayed
onAdDisplayFailed

LevelPlay Ad Info

Ad Info バナーリスナーコールバックによって返される AdInfo クラスは、LevelPlayAdInfo に置き換えられました。
その実装や利用可能なフィールドの詳細はこちらをご覧ください。

バナー広告のロード

バナー広告のロードには IronSource.loadBanner の代わりに loadAd を使用してください。

// Load the banner ad
levelPlayBanner.loadAd();
// Load the banner ad
levelPlayBanner.loadAd()

バナーリフレッシュの一時停止・再開

プラットフォームでリフレッシュ値が定義されている場合、コードでバナーリフレッシュを一時停止できます。バナー広告の自動リフレッシュを停止または再開するには、次のメソッドを利用してください。

Note: バナーが再度表示されると、停止した時点からリフレッシュまでの残り時間を消化します。
  • pauseAutoRefresh – バナー広告の自動リフレッシュを一時停止します。
  • resumeAutoRefresh – バナー広告の自動リフレッシュを再開します。
// Pause refresh
levelPlayBanner.pauseAutoRefresh();
// Resume refresh
levelPlayBanner.resumeAutoRefresh();
// Pause refresh
levelPlayBanner.pauseAutoRefresh()
// Resume refresh
levelPlayBanner.resumeAutoRefresh()

バナー広告を破棄する

バナーを破棄するには、destroy メソッドを呼び出してください。IronSource.destroyBannerの代わりに使用します。

破棄したバナーは再度表示できません。もう一度広告を表示したい場合は、新たな LevelPlayBannerAdView オブジェクトを作成してください。

levelPlayBanner.destroy()
levelPlayBanner.destroy();

マルチ広告ユニット対応バナー API

レガシー 広告ユニット(New)
Banner Layout IronSourceBannerLayout LevelPlayBannerAdView 
API loadBanner loadAd
destroyBanner destroy
loadBanner setPlacementName
LevelPlayAdSize.getWidth
LevelPlayAdSize.getHeight
pauseAutoRefresh
resumeAutoRefresh

バナー広告のフル実装例

下記はアダプティブバナーサイズを使ったバナー広告の作成・ロード例です。

public void createAndLoadBanner() {
    // Create the banner view and set the ad unit id
    LevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
    
    // Set the placement name (optional)
    levelPlayBanner.setPlacementName("placementName");
    
    // Create the adaptive ad size to support both adaptive, banner and leaderboard (recommended)  
    LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
    
    // Required when using createAdaptiveAdSize()
    if (adSize != null) {
        levelPlayBanner.setAdSize(adSize);
    }
    
    // Add the banner view to the container
    ViewGroup adContainer = findViewById(android.R.id.adContainer);
    adContainer.addView(levelPlayBanner);
    
    // Load the banner ad
    levelPlayBanner.loadAd();
    
    // To get actual banner layout size (either custom/standard size or adaptive)
    height = adSize.getHeight();
    width = adSize.getWidth();
}
fun createAndLoadBanner() {
    // Create the banner view and set the ad unit id
    val levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")
    
    // Set the placement name
    levelPlayBanner.setPlacementName("placementName")
    
    // Create the adaptive ad size to support both adaptive, banner and leaderboard
    val adSize = createAdaptiveAdSize(context)
    
    // Required when using createAdaptiveAdSize()
    adSize?.let { levelPlayBanner.setAdSize(it) }
    
    // Add the banner view to the container
    val adContainer = findViewById<ViewGroup>(R.id.adContainer)
    adContainer.addView(levelPlayBanner)
    
    // Load the banner ad
    levelPlayBanner.loadAd()
    
    // Get width and height for the container
    val width = adSize?.getWidth()
    val height = adSize?.getHeight()
}

LevelPlay Mediation デモアプリ

デモアプリでバナーの広告ユニット API をアプリに実装する方法を確認できます。

Android デモアプリ

完了!

これで新しいマルチ広告ユニット API を使って、アプリケーション内でバナー広告を配信できるようになりました。