Banner Integration For Android english - Hiroaki-Shinoda/Geniee-Android-SDK GitHub Wiki

Android Implementation of banner ads

Banner ads are placed at the bottom or the top of the application screen.
It can be deployed as an in-line advertising or icon-based advertising by size setting of AdZone.

Implementation preparation

Implementation preparation of banner ads,
you need to install the GenieeSDK to project, following StartGuide.
[Start Guide] (https://github.com/geniee-ssp/Geniee-Android-SDK/wiki/Install-Android-SDK)

Classes and interfaces

To delivery Android banner ads, you have to use the following class.

  • GNAdView: Get a banner ad in asynchronous, the class for display
  • GNAdEventListener: Banner advertising cycle event processing interface

Acquisition and display of banner ads

  1. 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;
    
  2. Declare the variable of GNAdView

    GNAdView adView;
    
  3. Initializes the instance of GNAdView

    • API Initialized
    public GNAdView(Context context, GNAdSize adSize, GNTouchType touchType) throws IllegalArgumentException
    
    • Example for API Initialized
    adView = new GNAdView(
            this,
            GNAdSize.W320H50,
            GNTouchType.TAP_AND_FLICK
    );
    adView.setAppId("YOUR_SSP_APP_ID");
    

contextParameter sets the Context of App.
adSizeParameter sets the size type of advertising.
touchTypeParameter sets the tab type of advertising.
YOUR_SSP_APP_ID sets management ID of AdsZones in Geniee.

  1. Add Ads to Screen

    final LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
    layout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
    
  2. When it is displayed the activity screen, load ads, and display ads.

    adView.startAdLoop();
    

Calling "startAdLoop ()", GNAdView starts to load ads,
to start automatically rotation display of ads.

  1. When the activity screen was hidden, to stop the rotation of display ads.

    adView.stopAdLoop();
    
  2. At the end of activity screen, and then free the resources of GNAdView.

    adView.clearAdView();
    
  • Example implementation of GNAdSampleBanner:

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);

    // Initializes 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 the size type of advertisement

It can be deployed as icon-based advertising or in-line advertising by the size type setting of AdZone.

  • Banner-based advertising : GNAdSize.W320H50、GNAdSize.W300H250、GNAdSize.W320H100

  • Icon-based advertising : GNAdSize.W57H57、GNAdSize.W76H76

    The definition of GNAdSize The meaning of definition
    GNAdSize.W320H50 320x50
    GNAdSize.W300H250 300x250
    GNAdSize.W320H100 320x100
    GNAdSize.W57H57 57x57
    GNAdSize.W76H76 76x76

Banner rotation (Refresh)

From the management screen, you can set the banner rotation (refresh).
If you set, automatically refreshed with ads interval specified number of seconds (30 to 120).
If you want to stop the refresh, it is possible with either the following methods.

  • From the management screen, and disable "Enable banner rotation".

  • Call stopAdLoop function.

    @Override
    protected void onPause() {
        super.onPause();
        if(adView != null){
            adView.stopAdLoop();
        }
    }
    

GNAdEventListener interface

  • Implement Interface function of GNAdEventListener, you 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 screen transition of the landing page

Landing page of the ad, to start an external browser by default.
CallBack function implementation of GNAdEventListener,
it is possible to start in-app browser with URL of the landing page.
In addition, by the return value of function, and control that you do not launch an external browser.
If it returns true, you need to request the application side landingURL.

  • YES → Start external browser.

  • NO → Don't start external browser.

    @Override
    public boolean onShouldStartInternalBrowserWithClick(String landingURL) {
        return false;
    }
    

Change of advertising display area and centering

You can do centering change the advertising display area in devices.

  • Example:Centering 320x50 ad. (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 simultaneously acquire multiple AdZones advertising

Simultaneous acquisition of multiple ads, and implemented in the following mounting method.

  • In order to obtain multiple AdZones of advertising at the same time,
    to initialize the instance by specifying the APPID of multiple AdZones.

  • You can simultaneously acquire up to 10 AdZones of ads.

  • Separate each APPID by a comma, please do not put a space between the APPID.

    multiAdViewRequest = new GNAdViewRequest(this, "APPID1,APPID2,APPID3,...,APPID10");
    
  • If you want to exclude ads duplicate when you get multiple AdsZones of advertising at the same time,
    please uncheck "whether to use banner rotation" each AdZones in the management screen.

Class and protocol

To get the multiple AdZones of Android advertising at the same time, use the following class.

  • GNAdViewRequest → Acquisition class multiple AdZones of ads in asynchronous
  • GNAdView → Advertising class displays
  • GNAdViewRequestListener → Use protocol to receive the advertising load results

Get Multiple AdZones of Ads

  1. Import GNAdViewRequest and GNAdView

    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;
    
  2. Implement GNAdViewRequestListener interface

    public class MultipleBannerSampleActivity extends ListActivity implements GNAdViewRequestListener {
    }
    
  3. Declare the variable of GNAdViewRequest

    GNAdViewRequest multiAdViewRequest;
    
  4. Initializes the instance of GNAdViewRequest

    multiAdViewRequest = new GNAdViewRequest(this, "APPID1,APPID2,APPID3,...,APPID10");
    

    thisParameter sets Context of App.

  5. Set listener of GNAdViewRequestListener
    The results of multiple ads load event, you will be notified via the listener.
    Set the instance variable implements GNAdViewRequestListener interface.

    multiAdViewRequest.setAdListener(this);
    
  6. Load the acquisition of multiple ads

    multiAdViewRequest.loadAds(this);
    

    thisParameter sets Context of App.

  7. Implementation of GNAdViewRequestListener interface
    Implement CallBack function of GNAdViewRequestListener, you will receive the results of ad 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 the array.
The distribution processing of multiple Ads, done in getAppId() information of GNAdView.
The number of elements in array adViews
- In case of one GNAdViewRequest , when you initialize, specify one App_ID
- In case of multi GNAdViewRequest,when you initialize, specify multi App_ID

  • Example implementation of 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;
}

} ```

Render Advertisements

Render acquired multiple ads

  • In order to Ad Rendering, it must be specifying display ad size.

    adLayout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
    adView.showBannerWithSize(width, height);
    adView.startAdLoop();
    
  • width → Advertising of width, advertising of width that you specified when you registered AdZone on the management screen

  • height → Advertising of height, height of the ad that you specified when you registered AdZone on the management screen

Done by specifying the advertising display area.

  • Example:Centering ads at 300x100 area. (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>
    

Example Rendering implementation

  • Example implementation of ArrayAdapter:
    @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

  • Advertising of rendering both, will be reported automatically impression is generated.
  • For impressions already been reported of advertising, it can not be reported again.
  • New advertising display, re-acquire the advertisement (or refresh) is required.

Ad click tracking

  • When Ads is clicked, to start the landing page of advertising in an external browser.
  • Automatically counts the number of times the ad click.

Control of screen transition of the landing page

Landing page of the ad, start an external browser by default.
CallBack function implementation of GNAdViewRequestListener,
it is possible to start in-app browser with the URL of the landing page.
In addition, by the return value of the function, and control that you do not launch an external browser.
If it returns true, you need to request the application side landingURL.

  • YES → Start the external browser

  • NO → Don't start the external browser

    @Override
    public boolean onShouldStartInternalBrowserWithClick(String landingURL) {
        return false;
    }
    

Simultaneous re-acquisition of multiple ads

  • The new ad, you must re-acquire ad.

    multiAdViewRequest.loadAds(this);
    

    thisParameter sets Context of App.