Android Implementation 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.

StartGuide

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

  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;
    
    1
    2
    3
    4
  2. Declare GRIdView of variable

    GNAdView adView;
    
    1
  3. Initialise an instance of GRIdView

    • Initialise API

      public GNAdView(Context context, GNAdSize adSize) throws IllegalArgumentException
      
      1

      or

      public GNAdView(Context context, GNAdSize adSize, GNTouchType touchType) throws IllegalArgumentException
      
      1
    • Example for initialise API

      adView = new GNAdView(this, GNAdSize.W320H50);
      adView.setAppId("YOUR_ZONE_ID");
      
      1
      2
    パラメータ名 内容
    context Context of App
    adSize Size type of advertising
    touchType Touch's type of advertising
    YOUR_ZONE_ID Management ID ad-zone in Geniee
  4. Add ads to screen

    final LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
    layout.addView(adView);
    
    1
    2
  5. At the time of display the activity screen, to load the ad and then displayed.

    adView.startAdLoop();
    
    1

When startAdLoop() is called then GNAdView start to load ads.
And it automatically starts the rotation display of advertising.

  1. At the end of activity screen, it allows to use resources of GNAdView.
    adView.clearAdView();
    
    1
  • 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);
    
            // Initializes a GNAdView
            adView = new GNAdView(this, GNAdSize.W320H50);
            adView.setAppId("YOUR_ZONE_ID");
            //adView.setLogPriority(GNAdLogger.INFO);
            //adView.setGeoLocationEnable(true);
            // Add AdView to view layer
            final LinearLayout layout = (LinearLayout)findViewById(R.id.AdviewLayout);
            layout.addView(adView);
            adView.startAdLoop();
        }
    
        @Override
        protected void onDestroy() {
            if (null != adView) {
                adView.clearAdView();
            }
            super.onDestroy();
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

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

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.

        if(adView != null){
            adView.stopAdLoop();
        }
        
    
    1
    2
    3
    4

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);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

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;
    }
    
    1
    2
    3
    4

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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:id="@+id/AdviewLayout"></LinearLayout>
1
2
3
4
5
6
Last Updated: 5/8/2019, 2:30:24 PM