MAX メディエーションネットワークの手動ダウンロード
リリースアップデートを受け取るには、AppLovin-MAX-SDK-iOS GitHubリポジトリ をサブスクライブしてください。
最新のAndroid SDKのダウンロード
プロジェクトへのSDKの追加
ダウンロードファイルを解凍し、aar
ファイルをプロジェクトのlibs
フォルダにドラッグアンドドロップします。
プロジェクトにlibs
フォルダがない場合は、app
フォルダ内に作成できます。
Gradle
build.gradle
ファイルに以下を追加します。
repositories { google() mavenCentral() flatDir { dirs 'libs' } ⋮}dependencies { implementation 'com.applovin:applovin-sdk:«x.y.z»@aar' ⋮}
repositories { google() mavenCentral() flatDir { dirs("libs") } ⋮}dependencies { implementation("com.applovin:applovin-sdk:«x.y.z»@aar") ⋮}
SDK Keyを追加
AndroidManifest.xml
のapplication
タグ内に次の行を追加します。
<meta-data android:name="applovin.sdk.key" android:value="«your-SDK-key»"/>
SDK KeyはAppLovinダッシュボードのAccount > General > Keys のセクションにてご確認ください。
Ad Reviewを有効化
MAX Ad Reviewサービスを有効にするには、build.gradle
ファイルに以下を追加します。
ルートレベルのbuild.gradle
ファイルへ追加
buildscript { repositories { maven { url 'https://artifacts.applovin.com/android' } } dependencies { classpath "com.applovin.quality:AppLovinQualityServiceGradlePlugin:+" }}
buildscript { repositories { maven { url = uri("https://artifacts.applovin.com/android") } } dependencies { classpath ("com.applovin.quality:AppLovinQualityServiceGradlePlugin:+") }}
アプリレベルのbuild.gradle
ファイルへ追加
apply plugin: 'applovin-quality-service'applovin { apiKey "«your-ad-review-key»"}
plugins { id("applovin-quality-service")}applovin { apiKey = "«your-ad-review-key»"}
Ad Review Keyは、AppLovinダッシュボードのAccount > General > Keys セクションでご確認ください。
MAX SDKを初期化
SDKの初期化構成を作成する
SDKを初期化する前に、SDKの初期化構成オブジェクトを作成します。
このオブジェクトを使用すると、SDKを初期化するプロパティを設定できます。
この初期化プロパティは変更不可ですが、例外としてAppLovinSdkSettings
には、アプリのライフタイムにおいて変更可能なプロパティが含まれます。
// Create the initialization configurationAppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»", this ) .setMediationProvider( AppLovinMediationProvider.MAX )// Perform any additional configuration/setting changes .build();
// Create the initialization configurationval initConfig = AppLovinSdkInitializationConfiguration.builder("«SDK-key»", this) .setMediationProvider(AppLovinMediationProvider.MAX)// Perform any additional configuration/setting changes .build()
SDK KeyはAppLovinダッシュボードのAccount > General > Keys のセクションにてご確認ください。
MAX SDKを初期化
初期化構成オブジェクトを使用して、AppLovin SDKを初期化します。例えば、ローンチアクティビティまたはアプリケーションクラスのonCreate()
内で、できるだけ早く初期化するようにしてください。
これにより、SDKがメディエーションネットワークの広告をキャッシュするまでの時間が最大化され、ユーザー体験の向上につながります。
public class MainActivity extends Activity{ protected void onCreate(Bundle savedInstanceState) { // Create the initialization configuration AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»", this ) .setMediationProvider( AppLovinMediationProvider.MAX ) .build();
// Initialize the SDK with the configuration AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener() { @Override public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig) { // Start loading ads } } ); }}
class MainActivity : Activity(){ override fun onCreate(savedInstanceState: Bundle?) { // Create the initialization configuration val initConfig = AppLovinSdkInitializationConfiguration.builder("«SDK-key»", this) .setMediationProvider(AppLovinMediationProvider.MAX) .build()
// Initialize the SDK with the configuration AppLovinSdk.getInstance(this).initialize(initConfig) { sdkConfig -> // Start loading ads } }}
例
以下は実装の例です。
// Create the initialization configurationAppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "«SDK-key»", this ) .setMediationProvider( AppLovinMediationProvider.MAX ) .setSegmentCollection( MaxSegmentCollection.builder() .addSegment( new MaxSegment( 849, Arrays.asList( 1, 3 ) ) ) .build() ) .build();
// Configure the SDK settings if needed before or after SDK initialization.val settings = AppLovinSdk.getInstance( this ).getSettings();settings.setUserIdentifier( "«user-ID»" );settings.setExtraParameter( "uid2_token", "«token-value»" );settings.getTermsAndPrivacyPolicyFlowSettings().setEnabled( true );settings.getTermsAndPrivacyPolicyFlowSettings().setPrivacyPolicyUri( Uri.parse( "«https://your-company-name.com/privacy-policy»" ) );settings.getTermsAndPrivacyPolicyFlowSettings().setTermsOfServiceUri( Uri.parse( "«https://your-company-name.com/terms-of-service»" ) );
// Initialize the SDK with the configurationAppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener(){ @Override public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig) { // Start loading ads }} );
// Create the initialization configurationval initConfig = AppLovinSdkInitializationConfiguration.builder("«SDK-key»", this) .setMediationProvider(AppLovinMediationProvider.MAX) .setSegmentCollection(MaxSegmentCollection.builder() .addSegment(MaxSegment(849, listOf(1, 3))) .build() ) .build()
// Configure the SDK settings if needed before or after SDK initialization.val settings = AppLovinSdk.getInstance(this).settingssettings.userIdentifier = "«user-ID»"settings.setExtraParameter("uid2_token", "«token-value»")settings.termsAndPrivacyPolicyFlowSettings.apply { isEnabled = true privacyPolicyUri = Uri.parse("«https://your-company-name.com/privacy-policy»") termsOfServiceUri = Uri.parse("«https://your-company-name.com/terms-of-service»")}
// Initialize the SDK with the configurationAppLovinSdk.getInstance(this).initialize(initConfig) { sdkConfig -> // Start loading ads}
インタースティシャル広告
インタースティシャルをロード
インタースティシャル広告をロードするには、広告ユニットでMaxInterstitialAd
オブジェクトをインスタンス化し、loadAd()
を呼び出します。
MaxAdListener
を実装すると、広告の準備ができた場合や、その他の広告関連イベントが発生した際に通知されるようになります。
public class ExampleActivity extends Activity implements MaxAdListener{ private MaxInterstitialAd interstitialAd; private int retryAttempt;
void createInterstitialAd() { interstitialAd = new MaxInterstitialAd( "«ad-unit-ID»", this ); interstitialAd.setListener( this );
// Load the first ad interstitialAd.loadAd(); }
// MAX Ad Listener @Override public void onAdLoaded(final MaxAd maxAd) { // Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
// Reset retry attempt retryAttempt = 0; }
@Override public void onAdLoadFailed(final String adUnitId, final MaxError error) { // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++; long delayMillis = TimeUnit.SECONDS.toMillis( (long) Math.pow( 2, Math.min( 6, retryAttempt ) ) );
new Handler().postDelayed( new Runnable() { @Override public void run() { interstitialAd.loadAd(); } }, delayMillis ); }
@Override public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) { // Interstitial ad failed to display. AppLovin recommends that you load the next ad interstitialAd.loadAd(); }
@Override public void onAdDisplayed(final MaxAd maxAd) {}
@Override public void onAdClicked(final MaxAd maxAd) {}
@Override public void onAdHidden(final MaxAd maxAd) { // Interstitial ad is hidden. Pre-load the next ad interstitialAd.loadAd(); }}
class ExampleActivity : Activity(), MaxAdListener{ private lateinit var interstitialAd: MaxInterstitialAd private var retryAttempt = 0.0
fun createInterstitialAd() { interstitialAd = MaxInterstitialAd( "«ad-unit-ID»", this ) interstitialAd.setListener( this )
// Load the first ad interstitialAd.loadAd() }
// MAX Ad Listener override fun onAdLoaded(maxAd: MaxAd) { // Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
// Reset retry attempt retryAttempt = 0.0 }
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) { // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++ val delayMillis = TimeUnit.SECONDS.toMillis( Math.pow( 2.0, Math.min( 6.0, retryAttempt ) ).toLong() )
Handler().postDelayed( { interstitialAd.loadAd() }, delayMillis ) }
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) { // Interstitial ad failed to display. AppLovin recommends that you load the next ad interstitialAd.loadAd() }
override fun onAdDisplayed(maxAd: MaxAd) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdHidden(maxAd: MaxAd) { // Interstitial ad is hidden. Pre-load the next ad interstitialAd.loadAd() }}
インタースティシャル広告を表示
インタースティシャル広告を表示するには、上記で作成したMaxInterstitialAd
オブジェクトでshowAd()
を呼び出します。
if ( interstitialAd.isReady() ){ interstitialAd.showAd();}
if ( interstitialAd.isReady ){ interstitialAd.showAd()}
リワード広告
リワード広告をロード
リワード広告をロードするには、リワード広告ユニットでMaxRewardedAd
オブジェクトを取得し、それに対してloadAd()
を呼び出します。
MaxRewardedAdListener
を実装すると、広告の準備ができた場合や、その他の広告関連イベントが発生した際に通知されるようになります。
public class ExampleActivity extends Activity implements MaxRewardedAdListener{ private MaxRewardedAd rewardedAd; private int retryAttempt;
void createRewardedAd() { rewardedAd = MaxRewardedAd.getInstance( "«ad-unit-ID»", this ); rewardedAd.setListener( this );
rewardedAd.loadAd(); }
// MAX Ad Listener @Override public void onAdLoaded(final MaxAd maxAd) { // Rewarded ad is ready to be shown. rewardedAd.isReady() will now return 'true'
// Reset retry attempt retryAttempt = 0; }
@Override public void onAdLoadFailed(final String adUnitId, final int errorCode) { // Rewarded ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++; long delayMillis = TimeUnit.SECONDS.toMillis( (long) Math.pow( 2, Math.min( 6, retryAttempt ) ) );
new Handler().postDelayed( new Runnable() { @Override public void run() { rewardedAd.loadAd(); } }, delayMillis ); }
@Override public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) { // Rewarded ad failed to display. AppLovin recommends that you load the next ad rewardedAd.loadAd(); }
@Override public void onAdDisplayed(final MaxAd maxAd) {}
@Override public void onAdClicked(final MaxAd maxAd) {}
@Override public void onAdHidden(final MaxAd maxAd) { // rewarded ad is hidden. Pre-load the next ad rewardedAd.loadAd(); }
@Override public void onUserRewarded(final MaxAd maxAd, final MaxReward maxReward) { // Rewarded ad was displayed and user should receive the reward }}
class ExampleActivity : Activity(), MaxRewardedAdListener{ private lateinit var rewardedAd: MaxRewardedAd private var retryAttempt = 0.0
fun createRewardedAd() { rewardedAd = MaxRewardedAd.getInstance( "«ad-unit-ID»", this ) rewardedAd.setListener( this )
rewardedAd.loadAd() }
// MAX Ad Listener override fun onAdLoaded(maxAd: MaxAd) { // Rewarded ad is ready to be shown. rewardedAd.isReady() will now return 'true'
// Reset retry attempt retryAttempt = 0.0 }
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) { // Rewarded ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++ val delayMillis = TimeUnit.SECONDS.toMillis( Math.pow( 2.0, Math.min( 6.0, retryAttempt ) ).toLong() )
Handler().postDelayed( { rewardedAd.loadAd() }, delayMillis ) }
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) { // Rewarded ad failed to display. AppLovin recommends that you load the next ad rewardedAd.loadAd() }
override fun onAdDisplayed(maxAd: MaxAd) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdHidden(maxAd: MaxAd) { // rewarded ad is hidden. Pre-load the next ad rewardedAd.loadAd() }
override fun onUserRewarded(maxAd: MaxAd, maxReward: MaxReward) { // Rewarded ad was displayed and user should receive the reward }}
リワード広告を表示
リワード広告を表示するには、上記で作成したMaxRewardedAd
オブジェクトでshowAd()
を呼び出します。
if ( rewardedAd.isReady() ){ rewardedAd.showAd();}
if ( rewardedAd.isReady() ){ rewardedAd.showAd();}
バナーおよびMREC
プログラムを利用してバナーやMRECをロードおよび表示する
バナー広告やミディアムレクタングル広告(MREC)をロードするには、広告ユニットでMaxAdView
オブジェクトを作成し、loadAd()
を呼び出します。
表示するには、MaxAdView
オブジェクトをビュー階層のサブビューとして追加してください。
MaxAdViewAdListener
を実装すると、広告の準備ができた場合や、その他の広告関連イベントが発生した際に通知されるようになります。
public class ExampleActivity extends Activity implements MaxAdViewAdListener{ private MaxAdView adView;
void createBannerAd() { adView = new MaxAdView( "«ad-unit-ID»", this ); 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 or background color for banners to be fully functional adView.setBackgroundColor( ... );
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 int errorCode) {}
@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) { /* use this for impression tracking */ }
@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 */ }}
class ExampleActivity : Activity(), MaxAdViewAdListener{ private var adView: MaxAdView? = null
fun createBannerAd() { adView = MaxAdView("«ad-unit-ID»", this) adView?.setListener(this)
// Stretch to the width of the screen for banners to be fully functional val width = ViewGroup.LayoutParams.MATCH_PARENT
// Banner height on phones and tablets is 50 and 90, respectively val heightPx = resources.getDimensionPixelSize(R.dimen.banner_height)
adView?.layoutParams = FrameLayout.LayoutParams(width, heightPx)
// Set background or background color for banners to be fully functional adView?.setBackgroundColor(...)
val rootView = findViewById<ViewGroup>(android.R.id.content) rootView.addView(adView)
// Load the ad adView?.loadAd() }
// MAX Ad Listener override fun onAdLoaded(maxAd: MaxAd) {}
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdExpanded(maxAd: MaxAd) {}
override fun onAdCollapsed(maxAd: MaxAd) {}
override fun onAdDisplayed(maxAd: MaxAd) { /* use this for impression tracking */ }
override fun onAdHidden(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }}
public class ExampleActivity extends Activity implements MaxAdViewAdListener{ private MaxAdView adView;
void createMrecAd { adView = new MaxAdView( "«ad-unit-ID»", MaxAdFormat.MREC, this ); 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 or background color for MRECs to be fully functional adView.setBackgroundColor( ... );
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 int errorCode) {}
@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) { /* use this for impression tracking */ }
@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 */ }}
class ExampleActivity : Activity(), MaxAdViewAdListener{ private var adView: MaxAdView? = null
fun createMrecAd { adView = MaxAdView("«ad-unit-ID»", MaxAdFormat.MREC, this) adView?.setListener(this)
// MREC width and height are 300 and 250 respectively, on phones and tablets val widthPx = AppLovinSdkUtils.dpToPx(this, 300) val heightPx = AppLovinSdkUtils.dpToPx(this, 250)
adView?.layoutParams = FrameLayout.LayoutParams(widthPx, heightPx)
// Set background or background color for MRECs to be fully functional adView?.setBackgroundColor(...)
val rootView = findViewById<ViewGroup>(android.R.id.content) rootView.addView(adView)
// Load the ad adView?.loadAd() }
// MAX Ad Listener override fun onAdLoaded(maxAd: MaxAd) {}
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdExpanded(maxAd: MaxAd) {}
override fun onAdCollapsed(maxAd: MaxAd) {}
override fun onAdDisplayed(maxAd: MaxAd) { /* use this for impression tracking */ }
override fun onAdHidden(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" />
<com.applovin.mediation.ads.MaxAdView xmlns:maxads="http://schemas.applovin.com/android/1.0" maxads:adUnitId="«ad-unit-ID»" maxads:adFormat="MREC" android:background="@color/mrec_background_color" android:layout_width="300dp" android:layout_height="250dp" />
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>
バナーまたはMREC広告を非表示にするには、次を呼び出します。
adView.setVisibility( View.GONE );adView.stopAutoRefresh();
adView.visibility = View.GONEadView.stopAutoRefresh()
バナーまたはMREC広告を表示するには、次を呼び出します。
adView.setVisibility( View.VISIBLE );adView.startAutoRefresh();
adView.visibility = View.VISIBLEadView.startAutoRefresh()
メディエーションネットワークの準備
連携するアドネットワークを選択して、表示される手順に従ってください。