コンテンツにスキップ

バナーおよびMREC広告

バナーおよびMREC広告は、アプリのレイアウトの一部を占める長方形の広告フォーマットです。多くの場合、画面の上部または下部に配置されるか、スクロール可能なコンテンツ内にインラインで配置されます。 ユーザーがアプリを操作している間も表示され続け、ゲームプレイやアプリの使用を妨げることなく広告を提示することが可能です。一定の時間が経過すると、自動的に広告が更新されるよう設定することもできます。

次のセクションでは、バナーまたはMREC広告をロードし、表示または非表示にする方法について説明します。

バナーまたはMRECのローディング

バナーやミディアムレクタングル広告(MREC)を表示するには、広告ユニットに対応するMaxAdViewオブジェクトを作成し、そのオブジェクトの loadAd()メソッドを呼び出します。 広告を表示するには、MaxAdView オブジェクトをビュー階層のサブビューとして追加します。 広告の準備が完了した際に通知されるように、MaxAdViewAdListenerを実装します。これにより、他の広告関連イベントも通知されます。

MREC広告をコンテンツフィードに表示することが連携に必要である場合、AppLovinは以下を推奨します。

  • 作成するインスタンス数を最低限に留める。
  • 自動更新を停止する。
  • loadAd() を呼び出してコンテンツを手動で更新します(MaxAdView インスタンスを再利用します)。

実装例については、AppLovinのデモアプリの(JavaKotlin)を参照してください。

バナー

public class ExampleActivity extends Activity
implements MaxAdViewAdListener
{
private MaxAdView adView;
void createBannerAd()
{
adView = new MaxAdView( "«ad-unit-ID»" );
adView.setListener( this );
// Stretch to the width of the screen for banners to be fully functional
int width = ViewGroup.LayoutParams.MATCH_PARENT;
// Banner height on phones and tablets is 50 and 90, respectively
int heightPx = getResources().getDimensionPixelSize( R.dimen.banner_height );
adView.setLayoutParams( new FrameLayout.LayoutParams( width, heightPx ) );
// Set background color for banners to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}
// MAX Ad Listener
@Override
public void onAdLoaded(final MaxAd maxAd) {}
@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error) {}
@Override
public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) {}
@Override
public void onAdClicked(final MaxAd maxAd) {}
@Override
public void onAdExpanded(final MaxAd maxAd) {}
@Override
public void onAdCollapsed(final MaxAd maxAd) {}
@Override
public void onAdDisplayed(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
@Override
public void onAdHidden(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}

MRECs

public class ExampleActivity extends Activity
implements MaxAdViewAdListener
{
private MaxAdView adView;
void createMRecAd
{
adView = new MaxAdView( "«ad-unit-ID»", MaxAdFormat.MREC );
adView.setListener( this );
// MREC width and height are 300 and 250 respectively, on phones and tablets
int widthPx = AppLovinSdkUtils.dpToPx( this, 300 );
int heightPx = AppLovinSdkUtils.dpToPx( this, 250 );
adView.setLayoutParams( new FrameLayout.LayoutParams( widthPx, heightPx ) );
// Set background color for MRECs to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}
// MAX Ad Listener
@Override
public void onAdLoaded(final MaxAd maxAd) {}
@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error) {}
@Override
public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) {}
@Override
public void onAdClicked(final MaxAd maxAd) {}
@Override
public void onAdExpanded(final MaxAd maxAd) {}
@Override
public void onAdCollapsed(final MaxAd maxAd) {}
@Override
public void onAdDisplayed(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
@Override
public void onAdHidden(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}

レイアウトエディターにバナーまたはMRECをロードして表示

別の方法として、ビューレイアウトXMLにMAXバナーまたはMRECを追加することもできます。 背景または背景色 (android:background) を設定して、広告が完全に動作することを確認してください。 バナーの場合は、幅 (android:layout_width) を画面の幅まで引き延ばしてください。 MRECの場合は、以下のようにandroid:adFormatを設定します。

<com.applovin.mediation.ads.MaxAdView
xmlns:maxads="http://schemas.applovin.com/android/1.0"
maxads:adUnitId="«ad-unit-ID»"
android:background="@color/banner_background_color"
android:layout_width="match_parent"
android:layout_height="@dimen/banner_height" />

res/values/attrs.xmlで、ベースとなるバナーの高さが50dpであることを宣言します。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="banner_height">50dp</dimen>
</resources>

res/values-sw600dp/attrs.xmlで、タブレットのバナーの高さが90dpであることを宣言します。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="banner_height">90dp</dimen>
</resources>

この場合も、以下の方法で作成したMaxAdViewで、loadAd()を呼び出す必要があります。

MaxAdView adView = findViewById( R.id.ad_view );
adView.loadAd();

バナーおよびMRECの破棄

MaxAdViewインスタンスが不要になった場合は、そのdestroy()メソッドを呼び出してリソースを解放します。 例えば、ユーザーが広告削除を購入した場合などがこれに該当します。 ただし、同じ広告ユニットIDを持つ複数のインスタンスを使用している場合は、destroy()メソッドを呼び出さないでください。

adView.destroy();

アダプティブバナー

Adaptive banners are responsive ads that dynamically adjust their dimensions based on device type and available width. Adaptive banners can either be anchored or inline, with each type serving specific integration needs.

Starting in MAX SDK version 13.2.0, you can integrate adaptive banners by initializing your MaxAdView with a MaxAdViewConfiguration object.

Anchored Adaptive Banners

Anchored adaptive banners are those you anchor at the top or bottom of the screen. They dynamically adjust their height based on the device type and the banner width.

You must set the height of the MaxAdView to the value returned by MaxAdFormat.BANNER.getAdaptiveSize( Context ).getHeight() instead of using a constant value like 50 or 90.

void createAnchoredAdaptiveBannerAd()
{
// Stretch to the width of the screen for banners to be fully functional
int width = ViewGroup.LayoutParams.MATCH_PARENT;
// Get the anchored adaptive banner height
int heightDp = MaxAdFormat.BANNER.getAdaptiveSize( this ).getHeight();
int heightPx = AppLovinSdkUtils.dpToPx( this, heightDp );
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.ANCHORED )
.build();
adView = new MaxAdView( "«ad-unit-ID»", config );
adView.setListener( this );
adView.setLayoutParams( new FrameLayout.LayoutParams( width, heightPx ) );
// Set background color for banners to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}

カスタム幅を設定する

For more specific integrations, you can configure a custom width in dp by calling a MaxAdViewConfiguration builder method (as of Google adapter version 21.5.0.3, Google Ad Manager adapter version 21.5.0.2, and Liftoff Monetize adapter version 7.4.3.2). To fetch the appropriate height for your custom anchored adaptive ad, call the adaptive size API.

int widthDp = 400;
// Get the anchored adaptive banner height
int heightDp = MaxAdFormat.BANNER.getAdaptiveSize( widthDp, context ).getHeight();
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.ANCHORED )
.setAdaptiveWidth( widthDp )
.build();
adView = MaxAdView( "«ad-unit-ID»", config );

インラインアダプティブバナー

Adaptive banners are anchored by default. Alternatively, you can enable inline adaptive banners, which you can place in scrollable content. Inline adaptive banners are typically larger than anchored adaptive banners. They have variable heights that can extend to the full height of the device screen.

Inline adaptive banners are supported starting with Android Google adapter version 23.2.0.1 and Liftoff Monetize adapter version 7.4.3.2. To enable inline adaptive banners, set the MaxAdViewConfiguration adaptive type to MaxAdViewConfiguration.AdaptiveType.INLINE as shown in the code below:

MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.INLINE )
.build();

The default maximum height for an inline adaptive ad is the entire height of the device screen. You may want to set a maximum height, in dp, for your inline adaptive ad to ensure that the ad is within the height of the MaxAdView. You can do this with code like the following, which uses a maximum height of 100 dp as an example:

MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.INLINE )
.setInlineMaximumHeight( 100 )
.build();

Inline Adaptive MRECs

You can integrate adaptive MRECs, starting with Android Google adapters version 23.6.0.3 and Liftoff Monetize adapter version 7.4.3.2. You must set inline adaptive MRECs to the type MaxAdViewConfiguration.AdaptiveType.INLINE for them to function properly.

Inline adaptive MRECs span the full width of the application window by default, but you may optionally specify a custom width in dp. The height is variable and can extend beyond standard MREC dimensions up to the full height of the device screen if you do not specify a maximum height. You configure an inline adaptive MREC as shown in the following example:

void createInlineAdaptiveMRecAd()
{
// Set a custom width, in dp, for the inline adaptive MREC. Otherwise stretch to screen width by using ViewGroup.LayoutParams.MATCH_PARENT
int widthDp = 400;
int widthPx = AppLovinSdkUtils.dpToPx( this, widthDp );
// Set a maximum height, in dp, for the inline adaptive MREC. Otherwise use standard MREC height of 250 dp
// Google recommends a height greater than 50 dp, with a minimum of 32 dp and a maximum equal to the screen height
// The value must also not exceed the height of the MaxAdView
int heightDp = 300;
int heightPx = AppLovinSdkUtils.dpToPx( this, heightDp );
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.INLINE )
.setAdaptiveWidth( widthDp ) // Optional: The adaptive ad will span the width of the application window if you do not set a value
.setInlineMaximumHeight( heightDp ) // Optional: The maximum height will be the screen height if you do not set a value
.build();
adView = new MaxAdView( "«ad-unit-ID»", MaxAdFormat.MREC, config );
adView.setListener( this );
adView.setLayoutParams( new FrameLayout.LayoutParams( widthPx, heightPx ) );
// Set background color for adaptive MRECs to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}

Handling Adaptive Ad Sizes

The adaptive ad you load could be smaller than the dimensions you requested. You may wish to configure your UI in a way that can adapt based on the size of the adaptive ad served. If so, you can retrieve the width and height of the loaded ad, in dp, with code like the following:

@Override
public void onAdLoaded(final MaxAd maxAd)
{
AppLovinSdkUtils.Size adViewSize = maxAd.getSize();
int widthDp = adViewSize.getWidth();
int heightDp = adViewSize.getHeight();
}

自動更新の停止と開始

広告を非表示にする場合や手動で更新する場合など、自動更新を停止したいときは以下のコードを使用します。

// Set this extra parameter to work around SDK bug that ignores calls to stopAutoRefresh()
adView.setExtraParameter( "allow_pause_auto_refresh_immediately", "true" );
adView.stopAutoRefresh();

以下のコードで、広告の自動更新を開始します。

adView.startAutoRefresh();

loadAd()を呼び出して、広告コンテンツを手動で更新します。 これは、自動更新を停止している場合にのみ実行できます。

adView.loadAd();