ネイティブ広告実装手順V2
まだ広告枠作成、SDKダウンロードを行っていない場合、下記リンク先を参照してください。
プロジェクトにSDKを追加していない場合、以下の方法でSDKを追加してください。
nendSDK ver3.2.0 からネイティブ広告のテキストや画像などの広告情報をアプリ側から個別で取得できるようになりました。
新しい機能を使った実装方法は以下の通りです。
まず、NendAdNativeClient
クラスのインスタンスを生成します。
続いて NendAdNativeClient
に用意された loadAd(NendAdNativeClient.Callback)
メソッドを使用し広告オブジェクトを取得します。
広告オブジェクトの取得に成功した場合はCallback関数の onSuccess
で広告オブジェクトの NendAdNative
が取得できます。
広告オブジェクトの取得に失敗した場合はCallback関数の onFailure
に NendError
が返されます。
Kotlin
// 広告クライアントのインスタンス生成
val client = NendAdNativeClient(this, spotId, "apiKey")
var nativeAd: NendAdNative? = null
...
// 広告オブジェクトのロード
client.loadAd(object : NendAdNativeClient.Callback {
override fun onSuccess(nendAdNative: NendAdNative) {
// この広告オブジェクトから各広告データが取得できます
nativeAd = nendAdNative
}
override fun onFailure(nendError: NendAdNativeClient.NendError) {
Log.d(TAG, "広告取得失敗: ${nendError.message}")
}
})
Java
// 広告クライアントのインスタンス生成
NendAdNativeClient mClient = new NendAdNativeClient(context, spotId, "apiKey");
NendAdNative mNendAdNative;
...
// 広告オブジェクトのロード
mClient.loadAd(new NendAdNativeClient.Callback() {
@Override
public void onSuccess(NendAdNative nendAdNative) {
// この広告オブジェクトから各広告データが取得できます
mNendAdNative = nendAdNative;
}
@Override
public void onFailure(NendAdNativeClient.NendError nendError) {
Log.d(TAG, "広告取得失敗:" + nendError);
}
});
インスタンス生成時に必要な情報は以下の通りです。
引数名 | 型 | 説明 |
---|---|---|
context | Context | |
spotId | int | 管理画面より発行されたSpotId |
apiKey | String | 管理画面より発行されたApiKey |
NendAdNative
オブジェクトから広告のテキストやBitmap
画像などの各データを取得し表示させます。
なお、ネイティブ広告はこちらのガイドラインに沿って表示させてください。
-
広告画像とロゴ画像
downloadAdImage
で広告画像、downloadLogoImage
でロゴ画像のBitmap
が取得可能です。
メソッドが成功すると、Callback関数のonSuccess
でBitmap
画像が取得できます。
失敗した場合、Callback関数のonFailure
にエラーメッセージが返されます。
また、各画像が含まれていない広告タイプでこれらのメソッドを使用すると、Callback関数のonFailure
にエラーメッセージが返されます。 -
広告画像URLとロゴ画像URLの取得について
getAdImageUrl
,getLogoImageUrl
を使用して画像のURLを取得できます。
取得したURLを使用してアプリ側で画像をダウンロードする事が可能です。
各画像が含まれていない広告タイプでこれらのメソッドを使用した場合はnull
が返されます。
取得項目 | 取得メソッド名 | 型 |
---|---|---|
広告画像 | downloadAdImage(NendAdNative.Callback()) |
Bitmap |
広告画像URL | getAdImageUrl() |
String |
ロゴ画像 | downloadLogoImage(NendAdNative.Callback()) |
Bitmap |
ロゴ画像URL | getLogoImageUrl() |
String |
広告見出し | getTitleText() |
String |
広告文 | getContentText() |
String |
プロモーション名 | getPromotionName() |
String |
表示URL | getPromotionUrl() |
String |
アクションボタン | getActionText() |
String |
広告明示 | NendAdNative.AdvertisingExplicitly.xxx.getText() |
String |
広告明示 に関しては、NendAdNative.AdvertisingExplicitly.xxx.getText()
で取得できます。
「xxx」部分は以下から選択できます。
定数 | 取得できるテキスト |
---|---|
NendAdNative.AdvertisingExplicitly.PR | PR |
NendAdNative.AdvertisingExplicitly.SPONSORED | Sponsored |
NendAdNative.AdvertisingExplicitly.AD | 広告 |
NendAdNative.AdvertisingExplicitly.PROMOTION | プロモーション |
Kotlin
// レイアウトの取得
val prText = findViewById(R.id.pr_text)
val titleText = findViewById(R.id.title_text)
val contentText = findViewById(R.id.content_text)
val promotionText = findViewById(R.id.promotion_name)
val promoUrlText = findViewById(R.id.promotion_url)
val actionText = findViewById(R.id.action_text)
val adImage = findViewById(R.id.ad_image)
// 広告明示の取得
prText.text = NendAdNative.AdvertisingExplicitly.SPONSORED.text
// 各広告文の取得
titleText.text = nendAdNative.titleText
contentText.text = nendAdNative.contentText
promotionText.text = nendAdNative.promotionName
promoUrlText.text = nendAdNative.promotionUrl
actionText.text = nendAdNative.actionText
// 広告画像の取得
nendAdNative.downloadAdImage(object : NendAdNative.Callback {
override fun onSuccess(bitmap: Bitmap) {
adImage.setImageBitmap(bitmap)
}
override fun onFailure(error: Exception) {
Log.d(TAG, "広告画像取得失敗: ${error.message}")
}
})
Java
// レイアウトの取得
TextView prText = findViewById(R.id.pr_text);
TextView titleText = findViewById(R.id.title_text);
TextView contentText = findViewById(R.id.content_text);
TextView promotionText = findViewById(R.id.promo_name_text);
TextView promoUrlText = findViewById(R.id.promo_url_text);
TextView actionText = findViewById(R.id.action_text);
ImageView adImage = findViewById(R.id.ad_image);
// 広告明示の取得
prText.setText(NendAdNative.AdvertisingExplicitly.SPONSORED.getText());
// 各広告文の取得
titleText.setText(mNendAdNative.getTitleText());
contentText.setText(mNendAdNative.getContentText());
promotionText.setText(mNendAdNative.getPromotionName());
promoUrlText.setText(mNendAdNative.getPromotionUrl());
actionText.setText(mNendAdNative.getActionText());
// 広告画像の取得
mNendAdNative.downloadAdImage(new NendAdNative.Callback() {
@Override
public void onSuccess(final Bitmap bitmap) {
adImage.setImageBitmap(bitmap);
}
@Override
public void onFailure(Exception error) {
Log.d(TAG, "広告画像取得失敗: " + error);
}
});
表示した広告をクリック可能にし、Impressionを送信するには、NendAdNative
オブジェクトに用意された activate
メソッドを使用します。
第一引数の adContainer には広告の各パーツを配置した親の View
を渡します。
第二引数の prTextView には「広告明示」をセットした TextView
を渡します。
これら二つの引数は 必須 となっています。
Kotlin
var nendAdNative: NendAdNative? = null
...
nendAdNative?.activate(adContainer, prTextView)
Java
NendAdNative mNendAdNative;
...
mNendAdNative.activate(adContainer, prTextView);
-
2023年9月1日より、SDK v6.0.0未満では動画広告の配信を停止いたします。新しいバージョンのご利用をご検討ください。
-
Google Play Consoleのデータセーフティに関して、nendSDKのデータ収集項目のページを追加しました。詳しくはこちらをご覧ください。
-
Android 13より、Google Advertising IDのアクセスのために権限の追加を強く推奨しています。詳しくはSDKの組み込み方法をご覧ください。
-
v9.0.0よりSDK内部の依存性及び位置情報機能の完全な削除を行いました。詳しくは更新履歴を御覧ください。
-
らくらくスマートフォンの
F-01L
にて、特定のOSバージョンでバナー広告利用時にアプリがクラッシュするという報告を一部のメディア様から頂いております。詳細はこちらをご確認ください。 -
Google Play Services r30 よりライブラリプロジェクトの提供がなくなり、今後はEclipseプロジェクトへのGoogle Play Servicesの導入が不可能となったため、nendSDKにおいてもEclispeでの導入・開発のサポートを終了させていただきました。
EclipseからAndroidStudioへの移行はこちらをご参照ください。 -
Googleのデベロッパーポリシーの更新に伴い、v3.1.0のSDKよりインタースティシャル広告のアプリ終了時表示機能を廃止させていただきました。
-
Effective September 1, 2023, we will stop serving video ads with SDK under v6.0.0. Please consider using a newer version.
-
For data safety section in Google Play Console, We added a page about data collection used on nendSDK. For details, please see here.
-
Since Android 13, we highly recommend add the permision to access Google Advertising ID. For details, please see About integrate the SDK.
-
In v9.0.0, a new dependency had been added to the sdk and all functions of collecting location data are completely deleted.
-
We have received reports from some media that a model of smartphone,
F-01L
crashes when using banner ads on a specific OS version. For details, please check here. -
nendSDK terminated the introduction and development support of Eclispe as Google Play Services (r30) no longer provides library project and impossible to install Google Play Services to the Eclispe project.
Please check the link below for how to transfer from Eclipse to AndroidStudio. -
With the update of Google Developer Policy, we terminated the function to show interstitial ads before the user closes the app from v3.1.0 SDK.
- バナー型広告
- アイコン型広告
- インタースティシャル広告
- ネイティブ広告
- フルボード広告
- 動画広告
- 動画ネイティブ広告
- Release Notes
- Preparation
- Supported Devices and IDE
- nendSDK Data Collection Items
- nendSDK Privacy Policy
- About Information Button
- Banner Ad
- Icon Ads
- Interstitial Ad
- Native Ad
- Fullscreen Ad
- Video Ad
- Native Video Ad