Android のバナー広告単位 API への移行
SDK の初期化、特定の広告単位 ID を持つバナー広告オブジェクトの作成、適応型または固定型のバナーサイズの設定、ロード、表示、更新などの広告イベントを管理するリスナーの実装によって、LevelPlay バナー Ad 単位 API を統合します。
読み終わるまでの所要時間 9 分最終更新 7日前
このガイドでは、現在の実装から LevelPlay バナー API (広告単位 ID を使用) に遷移し、バナー広告をロードしてディスプレイする方法について説明します。
前提条件
- サポートされている最小 SDK は 8.6.0 です。最新の SDK はここからダウンロードできます。
- LevelPlay 初期化 API を使用して SDK を初期化していることを確認します。
- LevelPlay ダッシュボードで AdUnitID を見つけます。
バナー広告オブジェクトの作成とサイズの設定
バナー広告オブジェクトの作成は、onInitSuccess コールバックの受信後に行う必要があります。
// Create the banner view and set the ad unit idLevelPlayBannerAdView levelPlayBanner = new LevelPlayBannerAdView(context, "adUnitId");
// Create the banner view and set the ad unit idval levelPlayBanner = LevelPlayBannerAdView(context, "adUnitId")
バナーサイズ
古い機能 | 広告単位(新規) | Dimensions in dp. |
|---|---|---|
| ISBannerSize | LevelPlayAdSize | (幅 X 高さ) |
| バナー | バナー | 320×50 |
| 大規模 | 大規模 | 728 x 90 |
| 矩形 | MEDIUM_RECTANGLE | 300 x 250 |
| スマート | Adaptive Ad Size (適応型広告サイズ) に置き換えられました (以下を参照)。 | 広告を自動的にレンダリングして、モバイルおよびタブレットのサイズと向きを調整 |
広告サイズを作成するには、以下のいずれかのオプションに従います。
**画面幅に合わせて調整できる適応型広告サイズ(推奨):**このオプションは、デバイス タイプに応じてバナーまたは LeaderBOARD を返します。適応特徴をサポートするネットワーク (Google、Yandex) は、最適化ロジックに基づいて高ささを返します。
LevelPlayAdSize adSize = LevelPlayAdSize.createAdaptiveAdSize(context);
val adSize = createAdaptiveAdSize(context)
**特定のバナーサイズ:**このオプションでは、バナーサイズを明確に設定できます。バナー、LARGE、MEDIUM_矩形。
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE);
levelPlayBanner.setAdSize(LevelPlayAdSize.MEDIUM_RECTANGLE)
Placements
バナーのプレースメントは、レポートの目的でのみサポートされます。プレースメントは**、loadAd** の前に設定して、リロードされたすべての広告に影響を与える必要があります。
// Set the placement namelevelPlayBanner.setPlacementName("placementName");
// Set the placement namelevelPlayBanner.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、エラー:LevelPlayAdError) { // Ad failed to be displayed on screen } override fun onAdClicked(adInfo:LevelPlayAdInfo) { // Ad was clicked } オーバーライド 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 }})
古い機能 | 広告単位 (新規) | |
|---|---|---|
| リスナー | LevelPlayBannerListener | LevelPlayBannerAdViewListener |
| コールバック | onAdLoaded | onAdLoaded |
| onAdLoadFailed | onAdLoadFailed | |
| onAdClicked | onAdClicked | |
| onAdScreenPresented | onAdExpanded | |
| onAdScreenDismissed | onAdCollapsed | |
| onAdLeftApplication | onAdLeftApplication | |
| onAdDisplayed | ||
| onAdDisplayFailed |
LevelPlay 広告情報
バナーリスナーのコールバックによって返される AdInfo クラスが LevelPlayAdInfo に置き換えられました。
ロードバナー広告
バナー広告をロードするには、Ironsource.loadBanner の代わりに loadAd を使用します。
// Load the banner adlevelPlayBanner.loadAd();
// Load the banner adlevelPlayBanner.loadAd()
バナー更新の一時停止と再開
プラットフォームで更新値が定義されている場合は、コードのバナー更新を一時停止できます。バナー広告の自動更新を停止するか、一時停止後に再度有効にするには、以下の方法を使用します。
- pauseAutoRefresh - バナー広告の自動更新を一時停止します。
- resumeAutoRefresh - バナー広告が一時停止された後、自動更新を再開します。
// Pause refreshlevelPlayBanner.pauseAutoRefresh();// Resume refreshlevelPlayBanner.resumeAutoRefresh();
// Pause refreshlevelPlayBanner.pauseAutoRefresh()// Resume refreshlevelPlayBanner.resumeAutoRefresh()
バナー広告の破棄
バナーを破棄するには、 Ironsource.destroyBanner の代わりに destroy メソッドを呼び出します。
破棄されたバナーは再度表示できなくなります。さらに広告を表示するには、新しい LevelPlayBannerAdView オブジェクトを作成します。
levelPlayBanner.destroy()
levelPlayBanner.destroy();
複数の広告単位バナーAPI
古い機能 | 広告単位 (新規) | |
|---|---|---|
| バナーのレイアウト | 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 デモアプリケーション
インテグレーション Demo (インテグレーションデモ) アプリケーションは、バナー広告単位 API をアプリケーションに統合する方法を示します。