Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Implementation for reward video ads

fan-mi-baba edited this page Oct 3, 2023 · 5 revisions

Advance Preparation

Please refer to the link below if you have not created ad spot or downloaded the SDK.

SDK Implementation

If you have not added the SDK to project, please add it with the following method.


Rewarded Video Ad Implementation

Implementation of rewarded video ad will be done with the following five steps.

  1. Generate Video Ad
  2. Load Video Ad
  3. Show Video Ad
  4. Release Video Ad
  5. Implement optional function

Generate Video Ad

First, generate the instance of NendAdRewardedVideo.

Kotlin
import net.nend.android.NendAdRewardedVideo
...

class VideoActivity : AppCompatActivity() {

    private lateinit var nendAdRewardedVideo: NendAdRewardedVideo

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        nendAdRewardedVideo = NendAdRewardedVideo(this, spotId, "apikey")
    }
}
Java
import net.nend.android.NendAdRewardedVideo;
...

public class MainActivity extends AppCompatActivity {

    NendAdRewardedVideo mNendAdRewardedVideo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mNendAdRewardedVideo = new NendAdRewardedVideo(this, spotId, "apikey");
    }
}

Information necessary for instance generation

Argument Type Description
context Context
spotId int Unique spot id for your app given by nend console
apiKey String Unique api key for your app given by nend console

Load Video Ad

Load the ad using loadAd.

Kotlin
nendAdRewardedVideo.loadAd()
Java
mNendAdRewardedVideo.loadAd();

You can get ad type information by type property.

type Description
NORMAL Reward video ads
PLAYABLE User-controllable ads

Show Video Ad

After confirming that loading of ad is completed by isLoaded, show the ad using showAd.

Kotlin
if (nendAdRewardedVideo.isLoaded) {
    nendAdRewardedVideo.showAd(this)
}
Java
if (mNendAdRewardedVideo.isLoaded()) {
    mNendAdRewardedVideo.showAd(this);
}

Release Video Ad

Please make sure to call the releaseAd method if your video ad session has been completed or will not use video ad again on onDestroy of Activity. Discard unnecessary resources for video ad with releaseAd method. Also, if called during loading of ad will also cancel that load. Also, if want to use video ad again after calling the releaseAd method, create an instance of NendAdRewardedVideo again.

Kotlin
nendAdRewardedVideo.releaseAd()  // release ad
Java
mNendAdRewardedVideo.releaseAd();  // release ad

Implement optional function

Please implement the following option as necessary. To acquire rewarded information, please register the following Event Listener.

Register Event Listener

Register event listener of NendAdVideoActionListener using setActionListener. NendAdVideo is the parent class of NendAdInterstitialVideo and NendAdRewardedVideo. The argument nendAdVideo in each NendAdRewardedActionListener listener is an object of NendAdRewardedVideo.

⚠️Notice about ads callback⚠️
Interactive ads (NendAdVideoType.PLAYABLE) cannot receive any event from NendAdVideoPlayingStateListener

Normal Video ads (NendAdVideoType.NORMAL) can receive callbacks when the video ads were played or stopped or finished.

Interactive ads (NendAdVideoType.PLAYABLE) is not video but working on the WebView.
Because of that, Interactive ads can't receive callback when the video ads were played or stopped or finished.

Kotlin
import net.nend.android.NendAdRewardItem
import net.nend.android.NendAdRewardedActionListener
import net.nend.android.NendAdVideo
...

nendAdRewardedVideo.setActionListener(object : NendAdRewardedActionListener {
    override fun onRewarded(nendAdVideo: NendAdVideo, nendAdRewardItem: NendAdRewardItem) {
        // Rewarded item was granted
        Log.d(TAG, "currencyName :
        ${nendAdRewardItem.currencyName}")  // Rewarded currency name
        Log.d(TAG, "currencyAmount :
        ${nendAdRewardItem.currencyAmount}")  // Rewarded currency amount
    }

    override fun onLoaded(nendAdVideo: NendAdVideo) {
        // loading of ad is completed

        when (nendAdVideo.type) {
            NendAdVideoType.PLAYABLE -> Log.d(TAG, "Playable ad is not provide playing state listener")
            NendAdVideoType.NORMAL -> {
                nendAdRewardedVideo.playingState()?.let {
                    it.playingStateListener = object : NendAdVideoPlayingStateListener {
                        override fun onStarted(nendAdVideo: NendAdVideo) {
                            // video started
                        }

                        override fun onStopped(nendAdVideo: NendAdVideo) {
                            // video stopped
                        }

                        override fun onCompleted(nendAdVideo: NendAdVideo) {
                            // video completed playing to the end
                        }
                    }
                }
            }
            else -> Log.d(TAG, nendAdVideo.type.toString())
        }

    }

    override fun onFailedToLoad(nendAdVideo: NendAdVideo, errorCode: Int) {
        // loading of ad is failed
        Log.d(TAG, "errorCode: $errorCode")
    }

    override fun onFailedToPlay(nendAdVideo: NendAdVideo) {
        // playing of ad content is failed
    }

    override fun onShown(nendAdVideo: NendAdVideo) {
        // ad shown
    }

    override fun onClosed(nendAdVideo: NendAdVideo) {
        // ad closed
    }

    override fun onAdClicked(nendAdVideo: NendAdVideo) {
        // ad clicked
    }

    override fun onInformationClicked(nendAdVideo: NendAdVideo) {
        // information button clicked
    }
})
Java
import net.nend.android.NendAdRewardItem;
import net.nend.android.NendAdRewardedActionListener;
import net.nend.android.NendAdVideo;
...

mNendAdRewardedVideo.setActionListener(new NendAdRewardedActionListener() {
    @Override
    public void onRewarded(NendAdVideo nendAdVideo, NendAdRewardItem rewardedItem) {
        // Rewarded item was granted
        Log.d(TAG, "currencyName:" +
        rewardedItem.getCurrencyName());  // Rewarded currency name
        Log.d(TAG, "currencyAmount:" +
        rewardedItem.getCurrencyAmount());  // Rewarded currency amount
    }

    @Override
    public void onLoaded(NendAdVideo nendAdVideo) {
        // loading of ad is completed
        switch (mNendAdRewardedVideo.getType()) {
            case PLAYABLE:
                Log.d(TAG, "Playable ad is not provide playing state listener");
                break;
            case NORMAL:
                NendAdVideoPlayingState state = mNendAdRewardedVideo.playingState();
                if (state != null) {
                    state.setPlayingStateListener(new NendAdVideoPlayingStateListener() {
                        @Override
                        public void onStarted(NendAdVideo nendAdVideo) {
                            // video started
                        }

                        @Override
                        public void onStopped(NendAdVideo nendAdVideo) {
                            // video stopped
                        }

                        @Override
                        public void onCompleted(NendAdVideo nendAdVideo) {
                            // video completed playing to the end
                        }
                    });
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onFailedToLoad(NendAdVideo nendAdVideo, int errorCode) {
        // loading of ad is failed
        Log.d(TAG, "errorCode:" + errorCode);
    }

    @Override
    public void onFailedToPlay(NendAdVideo nendAdVideo) {
        // playing of ad content is failed
    }

    @Override
    public void onShown(NendAdVideo nendAdVideo) {
        // ad shown
    }

    @Override
    public void onClosed(NendAdVideo nendAdVideo) {
        // ad closed
    }

    @Override
    public void onAdClicked(NendAdVideo nendAdVideo) {
        // ad clicked
    }

    @Override
    public void onInformationClicked(NendAdVideo nendAdVideo) {
        // information button clicked
    }
});
Acquire Rewarded Information

Rewarded information that can be acquire using the method of NendAdRewardItem from the argument rewardedItem of public void onRewarded(NendAdVideo nendAdVideo, NendAdRewardItem rewardedItem) of NendAdRewardedActionListener is as follows.

Method Type Description
getCurrencyName String Rewarded currency name
getCurrencyAmount int Rewarded currency amount
Acquire Error Information

The information of the argument errorCode of public void onFailedToLoad(NendAdVideo nendAdVideo, int errorCode) is as follows.

Code Description
204 No delivery ads
400 BAD request
5XX Server error
600 Error in SDK
601 Ad download failed
603 Invalid network

Set up User Name

This option is deprecated on nendSDK v10.0.0 or higher

When setting a user id that your app's original identifier, set the name with a character string using setUserId method.

Kotlin
nendAdRewardedVideo.setUserId("User Id")
Java
mNendAdRewardedVideo.setUserId("User Id");

Set up Features of User

This option is deprecated on nendSDK v10.0.0 or higher

In the nendSDK version 4.0.3 or higher, targeting-ad option of video ad is available to using Features of User. Here are available options.

  • Gender
  • Birthday
  • Age
  • Others: could be customized from own your app.
Kotlin
import net.nend.android.NendAdUserFeature
...

//e.g. Only single feature
val feature = NendAdUserFeature.Builder()
        .setBirthday(1985,1,1) // Birthday (e.g. Jan 1, 1985)
        .build()
nendAdRewardedVideo.setUserFeature(feature)

...

//e.g. Multiple features
val feature = NendAdUserFeature.Builder()
        .setGender(NendAdUserFeature.Gender.MALE) // Gender
        .setBirthday(1985, 1, 1) // Birthday (e.g. Jan 1, 1985)
        .setAge(34) // age
        .addCustomFeature("stringParameter", "test") // Others: customized parameters that formatted key-value type.
        .addCustomFeature("booleanParameter", true)
        .addCustomFeature("integerParameter", 100)
        .addCustomFeature("doubleParameter", 123.45)
        .build()
nendAdRewardedVideo.setUserFeature(feature)
Java
import net.nend.android.NendAdUserFeature;
...

//e.g. Only single feature
NendAdUserFeature feature = new NendAdUserFeature.Builder()
        .setBirthday(1985, 1, 1) // Birthday (e.g. Jan 1, 1985)
        .build();
mNendAdRewardedVideo.setUserFeature(feature);

...

//e.g. Multiple features
NendAdUserFeature feature = new NendAdUserFeature.Builder()
        .setGender(NendAdUserFeature.Gender.MALE) // Gender
        .setBirthday(1985, 1, 1) // Birthday (e.g. Jan 1, 1985)
        .setAge(34) // age
        .addCustomFeature("stringParameter", "test") // Others: customized parameters that formatted key-value type.
        .addCustomFeature("booleanParameter", true)
        .addCustomFeature("integerParameter", 100)
        .addCustomFeature("doubleParameter", 123.45)
        .build();
mNendAdRewardedVideo.setUserFeature(feature);

Note:

  • Birthday is high priority than age if set both parameters.
  • You can only using String or int or double or bool value at custom parameters.
  • If you want to set age group, please use custom parameters not age.

Verification

Please use one of the following test modes for video ads.

How to check GAID

  1. Enabled application logging.

  2. Generate reward video ad , then GAID value will be printed in debug logs. gaid_console_log

  3. Register GAID value on nend console.

日本語

nendSDK Android について

SDKの組み込み

広告の表示

ログ出力

導入サポート


English

About nendSDK Android

SDK Implementation

Display Ads

Logs Output

Supports

Clone this wiki locally