Create Android Adapter

Last Updated on: 19 Sep, 2023

Extend Base Adapter Class

Create a custom adapter class in Java/Kotlin with the naming convention as <span><</span><span>AdapterName</span><span>></span>SDKAdapter.

Kotlin

class <AdapterName>SDKAdapter : MesonBaseSDKAdapter { 
  // overrides the methods 
}

Java

public class <AdapterName>SDKAdapter implements MesonBaseSDKAdapter { 
    // Override the methods 
}

Initialize the Custom Network SDK

Override one of the initialization methods provided in the base adapter.

Asynchronous Initialization

initOnSDKInit(), method is provided by MesonBaseSDKAdapter to initialize custom network SDK asynchronously. The method return type is void.

Parameter Description
AdapterConfiguration All the network-related information required to initialize the custom network SDK. AdapterSDKConfiguration will have at least one of the required credentials; Network (Account ID), App (App ID), or Ad-Line (Placement ID).
MesonSdkInitializationListener This listener contains a single call back method onComplete(Error). The listener object should call onComplete() method with the null value if the network SDK is initialized successfully or else pass the Error object with the proper error message.

Kotlin

fun initOnSDKInit(adapterSdkConfig: AdapterSdkConfiguration, sdkListener: MesonSdkInitializationListener) {
      //Write the code to initialize the SDK asynchronously
}

Java

public void initOnSDKInit(@NonNull AdapterSdkConfiguration adapterSdkConfig, @NonNull MesonSdkInitializationListener sdkListener) {
      //Write the code to initialize the SDK asynchronously
}

Synchronous Initialization

initOnAdLoad(), the method is provided by MesonBaseSDKAdapter to initialize network SDK synchronously. The method return type is not void; it should return null if network SDK is initialized successfully or else Error object with the proper error message. 

Parameter Description
AdapterConfiguration All the network-related information required to initialize the custom network SDK. AdapterSDKConfiguration will have at least one of the required credentials; Network (Account ID), App (App ID), or Ad-Line (Placement ID).

Kotlin

fun initOnAdLoad(adapterConfig: AdapterSdkConfiguration): Error?

Java

public Error initOnAdLoad(@NonNull AdapterSdkConfiguration adapterConfig)

Set SDK Version

getSDKVersion(), override this method to return custom network SDK version.

Kotlin

override fun getSDKVersion(): String

Java

public String getSDKVersion()

Manage Ad Lifecycle

Create custom network SDK adapter classes per format with naming convention as AdapterNameFormatAdapter by extending the base format adapter classes.

Banner Ad

To create a custom network SDK Adapter class for Banner format extend the MesonBaseBannerAdapter.

Load Ad

load(), override this method in MesonBaseBannerAdapter to load ads from the custom network SDK.

Parameter Description
AdapterConfiguration All the network-related information required to initialize the custom network SDK. AdapterSDKConfiguration will have at least one of the required credentials; Network (Account ID), App (App ID), or Ad-Line (Placement ID).
MesonBannerAdapterListener This provides the ad lifecycle listener events.

Kotlin

override fun load(adapterConfig: AdapterAdConfiguration,listener: MesonBannerAdapterListener) {
    // Write the code to load network sdk ad
}

Java

@Override
public void load(@NonNull AdapterAdConfiguration adapterConfig,@NonNull MesonBannerAdapterListener listener) {
    // Write the code to load network sdk's banner ad
}

Return Banner Ad View

getAdView(), override this method in the MesonBaseBannerAdapter to return custom network SDKs banner ad view.

Kotlin

override fun isReady(): Boolean{
   // Write the code to verify whether network sdk is ready to show ad or not
}

Java

@Override
public boolean isReady(){
    // Write the code to verify whether network sdk is ready to show ad or not
}

Release Resources

invalidate(), override this method to release the resources.

Kotlin

override fun invalidate()

Java

public void invalidate()

Interstitial Ad

To create a custom network SDK Adapter class for Interstitial format extend the MesonBaseInterstitialAdapter.

Load Ad

load(), override this method in MesonBaseBannerAdapter to load the ad from the custom network SDK.

Parameter Description
AdapterConfiguration All the network-related information required to initialize the custom network SDK. AdapterSDKConfiguration will have at least one of the required credentials; Network (Account ID), App (App ID), or Ad-Line (Placement ID).
MesonInterstitialAdapterListener This provides the ad lifecycle listener events.

Kotlin

override fun load(adapterConfig: AdapterAdConfiguration,listener: MesonInterstitialAdapterListener) {
    // Write the code to load network sdk ad
}

Java

@Override
public void load(AdapterAdConfiguration adapterConfig,MesonInterstitialAdapterListener listener) {
     // Write the code to load network sdk's interstitial ad
}

Ad Load Success

isReady(), override this method to verify whether the custom network SDK has successfully loaded an ad. This method returns true if the custom network SDK is ready to show the ad or else returns false.

Kotlin

override fun isReady(): Boolean

Java

public boolean isReady()

Show Ad

show(), override this method to show interstitial or rewarded ads from the custom network SDK.

Kotlin

override fun show(){
    // Write the code to show the network sdk ad
}

Java

@Override
public void show(){
    // Write the code to show the network sdk ad
}

Release Resources

invalidate(), override this method to release the resources.

Kotlin

override fun invalidate(){
   // Write the code to release the network sdk resources
}

Java

@Override
public void invalidate(){
     // Write the code to release the network sdk resources
}

Rewarded Ad

To create a custom network SDK Adapter class for Rewarded format extend the MesonBaseRewardedAdapter.

Load Ad

load(), override this method in MesonBaseBannerAdapter to load ads from the custom network SDK.

Parameter Description
AdapterConfiguration All the network related information required to initialize the custom network SDK. AdapterSDKConfiguration will have atleast one of the required credentials; Network (Account ID), App (App ID) or Ad Line (Placement ID).
MesonRewardedAdapterListener This provides the ad lifecycle listener events.

Kotlin

override fun load(adapterConfig: AdapterAdConfiguration,listener: MesonRewardedAdapterListener) {
    // Write the code to load network sdk ad
 }

Java

@Override
public void load(AdapterAdConfiguration adapterConfig, MesonRewardedAdapterListener listener) {
     // Write the code to load network sdk's rewarded ad
}

Ad Load Success

isReady(), override this method to verify whether the custom network SDK has successfully loaded an ad. This method returns true if the custom network SDK is ready to show the ad or else returns false.

Kotlin

override fun isReady(): Boolean

Java

public boolean isReady()

Show Ad

show(), override this method to show interstitial or rewarded ads from the custom network SDK..

Kotlin

override fun show()

Java

public void show()

Release Resources

invalidate(), override this method to release the resources.

Kotlin

override fun invalidate()

Java

public void invalidate()