Banner Ads Integration For Android english - Hiroaki-Shinoda/Geniee-Android-SDK GitHub Wiki
Implementation Android Banner Ads
Banner ads are placed at bottom or top of application screen.
You can use as an icon-based advertising or in-line advertising depending on the ad size setting.
Preparation
To implement the banner ads, you need to install Geniee SDK to the project. Please follow the Start Guide for the process.
Classes and Interfaces
Use to deliver Android Banner ads following class.
- GNAdView get a banner ads asynchronous, class for display
- GNAdEventListener Banner ads cycle event processing interface
Display and get banner ads
-
Import
GNAdView
import jp.co.geniee.gnadsdk.banner.GNAdView; import jp.co.geniee.gnadsdk.common.GNAdLogger; import jp.co.geniee.gnadsdk.banner.GNAdSize; import jp.co.geniee.gnadsdk.banner.GNTouchType;
-
Declare
GRIdView
of variableGNAdView adView;
-
Initialise an instance of
GRIdView
- Initialise API
public GNAdView(Context context, GNAdSize adSize, GNTouchType touchType) throws IllegalArgumentException
- Example for initialise API
adView = new GNAdView( this, GNAdSize.W320H50, GNTouchType.TAP_AND_FLICK ); adView.setAppId("YOUR_SSP_APP_ID");
context parameter sets the Context of App.
adSize parameter sets size type of advertising.
touchType parameter sets tab type of advertising.
YOUR_SSP_APP_ID sets management ID ad-zone in Geniee.
-
Add ads to screen
final LinearLayout layout = (LinearLayout)findViewById(R.id.layout); layout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
-
At the time of display the activity screen, to load the ad and then displayed.
adView.startAdLoop();
When startAdLoop() is called then GNAdView start to load ads.
And it automatically starts the rotation display of advertising.
-
When Activity screen is hidden, it stops the rotation display of advertising.
adView.stopAdLoop();
-
At the end of activity screen, it allows to use resources of
GNAdView
.adView.clearAdView();
- Example GNAdSampleBanner implementation:
import jp.co.geniee.gnadsdk.common.GNAdLogger; import jp.co.geniee.gnadsdk.banner.GNAdView; import jp.co.geniee.gnadsdk.banner.GNAdSize; import jp.co.geniee.gnadsdk.banner.GNTouchType;
public class GNAdSampleBanner extends ActionBarActivity { private GNAdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gnad_sample_banner);
// Initialise a GNAdView
adView = new GNAdView(
this,
GNAdSize.W320H50,
GNTouchType.TAP_AND_FLICK
);
adView.setAppId("YOUR_SSP_APP_ID");
//adView.setLogPriority(GNAdLogger.INFO);
//adView.setGeoLocationEnable(true);
// Add AdView to view layer
final LinearLayout layout = (LinearLayout)findViewById(R.id.AdviewLayout);
layout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
}
@Override
protected void onResume() {
super.onResume();
if(adView != null){
adView.startAdLoop();
}
}
@Override
protected void onPause() {
super.onPause();
if(adView != null){
adView.stopAdLoop();
}
}
@Override
protected void onDestroy() {
if (null != adView) {
adView.clearAdView();
}
super.onDestroy();
}
} ```
Setting ad size type
You can deploy as icon-based advertising or in-line advertising based on the size type setting of ad inventory.
-
Banner-based advertising : GNAdSize.W320H50、GNAdSize.W300H250、GNAdSize.W320H100
-
Icon-based advertising : GNAdSize.W57H57、GNAdSize.W76H76
Definition GNAdSize The meaning of definition GNAdSize.W320H50 320x50 GNAdSize.W300H250 300x250 GNAdSize.W320H100 320x100 GNAdSize.W57H57 57x57 GNAdSize.W76H76 76x76
Banner Ads Rotation (Refresh)
From the management screen, you can set the interval of banner rotation advertisement.
If you set it, it automatically show the interval specified number of seconds (30 to 120).
If you want to stop the refresh ;
-
From management screen and disable the "Enable banner rotation".
-
Call the
stopAdLoop
function.@Override protected void onPause() { super.onPause(); if(adView != null){ adView.stopAdLoop(); } }
GNAdEventListener
Interface
-
Implement interface function of
GNAdEventListener
,
It will receive the advertisement processing cycle events.
public interface GNAdEventListener {
/**
* Call when GNAdView loaded ad data and first banner is shown.
* @param adView
*/
void onReceiveAd(GNAdView adView);
/**
* Call when GNAdView failed to load the ads.
* @param adView
*/
void onFaildToReceiveAd(GNAdView adView);
/**
* Call when built-in browser is starting.
* @param adView
*/
void onStartExternalBrowser(GNAdView adView);
/**
* Call when in-app browser is starting.
* @param adView
*/
void onStartInternalBrowser(GNAdView adView);
/**
* Called when in-app browser is terminating.
* @param adView
*/
void onTerminateInternalBrowser(GNAdView adView);
/**
* Call before built-in browser starting.
* @param landingURL
*/
boolean onShouldStartInternalBrowserWithClick(String landingURL);
} ```
Control of landing page screen transition
・Landing page ad is started an external browser by default setting.
・Implement Callback function of GNAdEventListener
,
it is possible to start in App within browser by using URL of landing page.
・it control the start-up of an external browser by return value of the function.
・If it returns true, you need to request the application side landingURL.
-
false Start-up an external browser
-
true Not start-up an external browser
@Override public boolean onShouldStartInternalBrowserWithClick(String landingURL) { return false; }
Change and the centering of advertising display area
You can centering and change the advertising display area in devices.
-
Example:Set Ad of 320x50 in center. (layout/activity_gnad_sample_banner.xml)
<LinearLayout android:id="@+id/AdviewLayout" android:layout_width="320dp" android:layout_height="50dp" android:layout_gravity="center_horizontal" android:orientation="vertical"> </LinearLayout>
Implementation to get multiple AdZones at the same time
Instruction on how to get more advertising at the same time;
-
In the same time you get multiple AdZones and initialize instance by specifying the APPID of multiple AdZones.
-
You can simultaneously get 10 AdZones.
-
Separate each APPID by a comma, please do not put a space between the APPID.
multiAdViewRequest = new GNAdViewRequest(this, "APPID1,APPID2,APPID3,...,APPID10");
-
The duplication of advertising acquired at the same time in multiple AdZones,
please uncheck "whether to use banner rotation" of each AdZones in management screen.
Classes and interfaces
Ad simultaneous acquisition Android multiple AdZones, use the following class.
- GNAdViewRequest Class to get multiple AdsZones of ads in asynchronous
- GNAdView Advertising class that displays
- GNAdViewRequestListener Use interface to receive results of advertising load
Get Multiple AdZones of Ads
-
Import
GNAdViewRequest
andGNAdView
import jp.co.geniee.gnadsdk.banner.GNAdView; import jp.co.geniee.gnadsdk.banner.GNAdViewRequest; import jp.co.geniee.gnadsdk.banner.GNAdViewRequestListener; import jp.co.geniee.gnadsdk.common.GNAdLogger;
-
Implement interface of
GNAdViewRequestListener
public class MultipleBannerSampleActivity extends ListActivity implements GNAdViewRequestListener { }
-
Declare a variable of
GNAdViewRequest
GNAdViewRequest multiAdViewRequest;
-
Initializes an instance of
GNAdViewRequest
multiAdViewRequest = new GNAdViewRequest(this, "APPID1,APPID2,APPID3,...,APPID10");
thisParameter sets the Context of App.
-
Set
GNAdViewRequestListener
listener
The results of multiple ads load event, will be notified via listener.
You set a instance variableGNAdViewRequestListener
interface was implemented.multiAdViewRequest.setAdListener(this);
-
Load multiple ads
multiAdViewRequest.loadAds(this);
thisParameter sets Context of App.
-
Implement
GNAdViewRequestListener
interface
Implement Callback function ofGNAdViewRequestListener
to receive results Ads load event.public abstract void onGNAdViewsLoaded(GNAdView[] adViews); public abstract void onGNAdViewsFailedToLoad(); public abstract boolean onShouldStartInternalBrowserWithClick(String landingURL);
Received advertisement GNAdView
is passed in adViews
argument of array.
The distribution processing of multiple ads use getAppId ()
information of GNAdView
.
The number of elements in the array adViews
:
- When one GNAdViewRequest
initialization, if you specify one APP_ID
- When multiplex GNAdViewRequest
initialization, if you specify multiple APP_ID
- Example for implement ListActivity:
import jp.co.geniee.gnadsdk.banner.GNAdView; import jp.co.geniee.gnadsdk.banner.GNAdViewRequest; import jp.co.geniee.gnadsdk.banner.GNAdViewRequestListener; import jp.co.geniee.gnadsdk.common.GNAdLogger;
public class MultipleBannerSampleActivity extends ListActivity implements GNAdViewRequestListener { GNAdViewRequest multiAdViewRequest;
@Override
public void onCreate(Bundle savedInstanceState) {
multiAdViewRequest = new GNAdViewRequest(this, "YOUR_SSP_APP_IDS");
multiAdViewRequest.setAdListener(this);
//multiAdViewRequest.setGeoLocationEnable(true);
//multiAdViewRequest.setLogPriority(GNAdLogger.INFO);
multiAdViewRequest.loadAds(this);
}
@Override
public void onGNAdViewsLoaded(GNAdView[] adViews) {
for(int i=0; i<adViews.length; i++) {
queueAds.enqueue(adViews[i]);
}
}
@Override
public void onGNAdViewsFailedToLoad() {
}
@Override
public boolean onShouldStartInternalBrowserWithClick(String landingURL) {
return false;
}
} ```
Rendering Ads
Rendering to get multiple ads
-
In order to Ad Rendering, you must specify display area size and ad size.
adLayout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); adView.showBannerWithSize(width, height); adView.startAdLoop();
-
Width :Ad's width that you specified when frame registered in the management screen
-
Height advertising of height that you specified when frame registered in the management screen
Done by specifying the advertising display area.
-
Example: centering in the area of 300x100 ads. (layout/ad_item.xml)
<LinearLayout android:id="@+id/ad_layout" android:layout_width="300dp" android:layout_height="100dp" android:layout_gravity="center_horizontal" android:orientation="vertical"> </LinearLayout>
Rendering implementation
- Example for ArrayAdapter implementation:
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; int type = getItemViewType(position); if (convertView == null) { holder = new ViewHolder(); switch (type) { case TYPE_AD: convertView = inflater.inflate(R.layout.ad_item, null); holder.adLayout = (LinearLayout)convertView.findViewById(R.id.ad_layout); break; case TYPE_ITEM: convertView = inflater.inflate(R.layout.list_item, null); holder.textView = (TextView) convertView.findViewById(R.id.textView); holder.imageView = (ImageView) convertView.findViewById(R.id.imageView); break; } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Object cell = getItem(position); // Rendering SDK GNAdView content if (cell instanceof GNAdView) { holder.adLayout.removeAllViews(); GNAdView adView = (GNAdView)cell; if (adView.getParent() == null) { holder.adLayout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); adView.showBannerWithSize(300, 100); adView.startAdLoop(); } } else { // Display processing of the cell than GNAdView. } return convertView; }
Ad impressions Report
Impression of generation timing
- The advertising of rendering both will be reported automatically when impression is generated.
- For impressions that has already been reported of advertising, can not be reported again.
- New advertising display, re-acquire the advertisement (or refresh) is required.
Ad click tracking
- When Ad is clicked,it leads to landing page of advertising in an external browser.
- Automatically counts number of times the ad click.
Control of the landing page screen transition
Callback function implementation of GNAdViewRequestListener
,
With the URL of the landing page it is possible to start in-app browser.
In addition, by the return value of the function you can control the start-up of an external browser.
If it returns true, you need to request application side landingURL.
-
Start the false external browser.
-
Do not start the true external browser.
@Override public boolean onShouldStartInternalBrowserWithClick(String landingURL) { return false; }
To re-acquire multiple ads at the same time
-
You will need to re-acquire ad, to display new ad
multiAdViewRequest.loadAds(this);
thisParameter sets Context of App.