ConsoliAds Standalone Integration

You are here:
Estimated reading time: 5 min

Download ConsoliAds Native SDK

Download ConsoliAds Android SDK here

Create App on Portal

Login to your ConsoliAds portal and go to Apps-> New App to create your native app. Make sure that you have already created a brand to associate your app with. Provide all the required information and save, ConsoliAds will create your app with the following default placeholders:

•  Activity 1

•  Activity 2

•  Activity 3

•  Activity 4

•  Options A

•  Options B

•  About

•  Settings

Integrating ConsoliAds

After downloading ConsoliAds standalone SDK, copy all files from zip to your android project inside “libs” folder. Please create “libs” folder inside your Android Studio app if it does not exists. Open your Project level “build.gradle” write following under allprojects -> repositories section.

 flatDir {
dirs 'libs'
}

Open your app level “build.gradle” and write the following lines in the dependencies section, to import ConsoliAds SDK:

implementation(name: 'standaloneSdkWrapper', ext: 'aar')
implementation(name: 'consoliadsplugin', ext: 'aar')
implementation(name: 'loaderlibrary', ext: 'aar')

ConsoliAds Dependencies

ConsoliAds SDK requires the following libraries as dependencies. Open your app level “build.gradle” and add the following dependencies:

implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.google.code.gson:gson:2.8.5'

Initializing ConsoliAds

Before initializing ConsoliAds SDK, you need to make sure that the app is created on ConsoliAds dashboard (go to the section New App on the portal). For initializing ConsoliAds SDK, you need to provide your app’s Product Name and Bundle Identifier as follows:

ConsoliAds.Instance().productName = "Fitness Guide";

ConsoliAds.Instance().bundleIdentifier = "com.mystudio.fitnessguide";

Please import the required packages for the above (HINT: click on the above line then press (Alt + Enter) to make instant import).

ConsoliAds also provides callbacks for events such as initialization, native ad loaded, etc. Your activity needs to extend the abstract class “ConsoliAdsListener” and override your required callback methods to receive event callbacks and register callback events as follows:

private class Listener extends ConsoliAdsListener
{
}

Now register the interface as follows:

ConsoliAds.Instance().setConsoliAdsListener(new Listener());

Initialize ConsoliAds mediation by:

ConsoliAds.Instance().initialize(true,this); 

This call requires the following mandatory parameters:

User Consent

TRUE means user has provided the consent and will be shown personalized ads, whereas FALSE means user is not willing to see personalized ads. It is developer’s responsibility to get user consent and pass it in initialization call.

Activity

The prevailing activity upon initialization.

Interstitial Ad

Once initialized, ConsoliAds SDK is ready to show ads.

•  Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
•  Add Interstitial and Video Ad slot as shown in the below figure:

Now show interstitial ad by simply the following code:

NOTE: Interstitial ads are not required to be requested and loaded separately

ConsoliAds.Instance().ShowInterstitial(sceneIndex, Activity);

This call requires the following mandatory parameters:

Scene Index

Integer value for the index of the scene for which you want to show the Interstitial ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.

Activity

The prevailing activity when showing the interstitial ad.

Rewarded Video

•  Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
•  Add Rewarded Video Ad slot as shown in the below figure:

Load Rewarded Video

Rewarded video ads in ConsoliAds are loaded and shown separately. Load rewarded video ad as follows:

 ConsoliAds.Instance().LoadRewarded(sceneIndex); 

NOTE: It is highly recommended that you call LoadRewarded(sceneIndex) as early as possible to allow videos to be preloaded.

This call requires the following mandatory parameter:

Scene Index

Integer value for the index of the scene for which you want to load the rewarded video ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.

Show Rewarded Video

Show Rewarded ad by simply the following code:

 ConsoliAds.Instance().ShowRewardedVideo(sceneIndex , Activity); 

This call requires the following two parameters:

Scene Index

Integer value for the index of the scene for which you want to show the rewarded video ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.

Activity

The prevailing activity when showing the rewarded video ad.

Banner Ad

•  Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
•  Add Banner Ad slot as shown in the below figure:

Show banner ad by simply the following code:

 ConsoliAds.Instance().ShowBanner(sceneIndex, Activity);

This call requires the following two parameters:

Scene Index

Integer value for the index of the Scene for which you want to show the banner ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.

Activity
The prevailing activity when showing the banner ad.
NOTE: ConsoliAds SDK supports one banner per activity.

Native Ad

Native Ad

ConsoliAds is the platform that helps you integrate native ads. It follows two approaches:

•  Single Native Integration – native ad for a single placeholder

•  Multiple Native Integration – native ad on a list activity

•  Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
•  Add Native Ad slot as shown in the below figure:

 

Show Single Native Ad

Single native ad integration configures the display content and let’s ConsoliAds handle the ad placement.

•  ConsoliAds

  ○  Configure ConsoliAds native ad
Add the following required widgets in xml and reference it in your activity and pass them to Configure Method as :

LinearLayout adContainer = (LinearLayout) findViewById(R.id.native_container);
TextView adTitle = (TextView) findViewById(R.id.tv_ad_title);
TextView adSubTitle = (TextView) findViewById(R.id.tv_ad_sub_title);
TextView adDescription = (TextView) findViewById(R.id.tv_ad_description);
ImageView adImage = (ImageView) findViewById(R.id.iv_ad_image);
AdChoices adChoices = (AdChoices) findViewById(R.id.native_adchoices_main);
ActionButton actionButton = (ActionButton) findViewById(R.id.native_action_button);


ConsoliAds.Instance().ConfigureConsoliadsNativeAd(currentScene,adContainer,adChoices,adTitle,adSubTitle,adDescription,

adImage,actionButton);

○  Show ConsoliAds Native Ad

ConsoliAds.Instance().ShowNativeAd(currentScene , this);

Note: XML structure for Native Ad of every ConsoliAds is present in “XML STUCTURE FOR NATIVE ADS” section below:

Events to listen for Native Ads:

1. public void onNativeAdLoadedEvent(AdNetworkName adNetworkName)

2. public void onNativeAdFailedToLoadEvent(AdNetworkName adNetworkName)

Load Multipe Native Ads

Note: To load multiple native ads on the same scene, call the above method multiple times.

Scene Index

Integer value for the index of the Scene for which you want to show the Native ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.

To use Typecast the object returned by getNativeAd and check for null as follows:

 NativeAd nativeAd = (NativeAd) ConsoliAds.Instance().getNativeAd (SceneIndex); if(nativeAd != null)

{

}

Icon Ad

•  Icon ad comes in different sizes (Small, Medium, Large)

•  Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads

•  Add icon ad slot

 

Steps to show Icon Ad

•  Add the following xml in your required activity view:


<com.consoliads.sdk.iconads.IconAdView
android:id="@+id/consoli_icon_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.consoliads.sdk.iconads.IconAdView>

•  Add the following code in your activity java file:

IconAdView iconAdView = findViewById(R.id.consoli_icon_view);

•  Get and show icon ad:

IconAdBase iconAdBase = (IconAdBase) ConsoliAds.Instance().getIconAdView(currentScene , MainActivity.this);
If( iconAdBase != null ){
iconAdView.setIconAd(iconAdBase);
}

Configure Server

Configure server is a mandatory step. First, check for java support by typing the following command in command prompt (or terminal in mac):

java -version

Find “libConfigureServer.jar” in ConsoliAds-sdk package and place it in root directory of the project. Now open command prompt (or terminal in mac) and go to root directory of the project to run the following command:

java -jar libConfigureServer.jar userSignature AppPackage platform

Example:

java -jar libConfigureServer.jar a023c0e11a55e3eb312658a1b57f3b30 com.seasonapps.myfitnessguide google

ConsoliAds SDK Sample App

You can download sample ConsoliAds project here

ConsoliAds SDK List View Sample App

You can find ConsoliAds sample application using list view for showing native ads inside list view in Android. You can also find it in the documentation.

XML STRUCTURE FOR NATIVE ADS

For ConsoliAds Native Ad Following Elements Are Required:

<LinearLayout
android:visibility="gone"
android:layout_marginBottom="8dp"
android:id="@+id/native_container"
android:orientation="vertical"
android:background="#FFF"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/ad"
android:textStyle="bold"
android:textColor="#FFF"
android:background="#FAA845"
android:textSize="10sp"
android:padding="2dp"
android:text="Ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:layout_toRightOf="@+id/ad"
android:textStyle="bold"
android:textColor="#FAA845"
android:textSize="10sp"
android:padding="2dp"
android:text="Consoliads"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<com.consoliads.sdk.nativeads.AdChoices
android:id="@+id/native_adchoices_main"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">

</com.consoliads.sdk.nativeads.AdChoices>

</RelativeLayout>

<LinearLayout
android:layout_margin="8dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:textSize="16sp"
android:id="@+id/tv_ad_title"
android:textStyle="bold"
android:textColor="@android:color/holo_blue_dark"
android:text="Drone Builder Kit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/iv_ad_image"
android:scaleType="fitXY"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="150dp" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_ad_sub_title"
android:textStyle="bold"
android:text="Circuit Scribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:layout_marginRight="8dp"
android:layout_alignParentLeft="true"
android:layout_alignLeft="@+id/native_action_button"
android:layout_below="@id/tv_ad_sub_title"
android:id="@+id/tv_ad_description"
android:textSize="10sp"
android:textStyle="bold"
android:text="Our new DIY Drone Builder Kit lets you build"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<com.consoliads.sdk.nativeads.ActionButton
android:layout_centerVertical="true"
android:id="@+id/native_action_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

</com.consoliads.sdk.nativeads.ActionButton>

</RelativeLayout>

</LinearLayout>

</LinearLayout>

ConsoliAds GitHub forum

If you are having any technical issues you can visit https://github.com/teamconsoliads/sampleapp-android to view known issues, share problems and suggestions.

Was this article helpful?
Dislike 0
Views: 275