Banner Ads Integration For Android English - kazTera/GYSDK_Android 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>