> For the complete documentation index, see [llms.txt](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md).

# I2WAPI

**package com.intowow\.sdk**

**public class I2WAPI**

This class is SDK main program class.

### Initialize SDK

* You should add `I2WAPI.init()`, `I2WAPI.onActivityResume()` and `I2WAPI.onActivityPause()` to all of the activities. In order to let the integration more simplified, we recommend you to add these API to your Application class:

```java
public class BaseApplication extends Application {

  private static final boolean IS_SUPPORT_LIFECYCLE_CALLBACKS = 
    (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
  private static BaseApplication mInstance = null;

  @Override
  public void onCreate() {    
    super.onCreate();
    mInstance = this;

    if(IS_SUPPORT_LIFECYCLE_CALLBACKS) {
      mInstance.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
          //  TODO
          //  Initilize intowow sdk
          //
          boolean isTestMode = is use test ad or not.
          boolean isOpenVerboseLog = is open verbose log or not.

          I2WAPI.init(activity.getApplicationContext(), isTestMode, isOpenVerboseLog);
        }

        @Override
        public void onActivityStarted(Activity activity) {
        }

        @Override
        public void onActivityResumed(Activity activity) {
          //  TODO
          //  Notify sdk that Activity has already in resume status
          //
          I2WAPI.onActivityResume(activity.getApplicationContext());
        }

        @Override
        public void onActivityPaused(Activity activity) {
          //  TODO
          //  Notify sdk that Activity has already in pause status
          //
          I2WAPI.onActivityPause(activity.getApplicationContext());
        }

        @Override
        public void onActivityStopped(Activity activity) {
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity,
          Bundle outState) {
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
        }
      });
    }
  }
}
```

* If you initialize SDK by `init(Context context, boolean isTestAd)` or `init(Context context, boolean isTestAd, boolean isVerbose)`, **be sure to configure the isTestAd and isVerbose to** `false` **before you release the build to the production environment.**&#x20;

| Public methods |                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#blockAd">blockAd(Context context, Ad ad, int reason, String description)</a> <br> Block an ad.</p>                                                                                                                                                                                                |
| JSONObject     | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#getAdditionalInfo">getAdditionalInfo(Context context)</a> <br> Get SDK additional info. such as device id, SDK version etc.</p>                                                                                                                                                                   |
| List\<Long\[]> | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#getAdditionalInfo-1">getAdsValidTime(Context context, String placement) </a></p><p>Return the ad valid time slot array by placement.</p>                                                                                                                                                          |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#init1">init(Context context)</a> <br> Initialize sdk.</p>                                                                                                                                                                                                                                         |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#init2">init(Context context, boolean isTestAd)</a> <br> Initialize sdk.</p>                                                                                                                                                                                                                       |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#init3">init(Context context, boolean isTestAd, boolean isVerbose)</a> <br> Initialize sdk.</p>                                                                                                                                                                                                    |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#onActivityResume">onActivityResume(Context context)</a> <br> Notify sdk that Activity has already in resume status.</p>                                                                                                                                                                           |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#onActivityPause">onActivityPause(Context context)</a> <br> Notify sdk that Activity has already in pause status.</p>                                                                                                                                                                              |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#preload">preload(Context context, String placement)</a> <br> Notify the SDK to preload this placement.</p>                                                                                                                                                                                        |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#preload2">preload(Context context, RequestInfo requestInfo)</a> <br> Notify the SDK to preload this placement by RequestInfo.</p>                                                                                                                                                                 |
| boolean        | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#hasReadyAd">hasReadyAd(Context context, String placement)</a> <br> Return true if there is at least one ready ad, otherwise return false.</p>                                                                                                                                                     |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#setAdUrlLoadingListener">setAdUrlLoadingListener(Context context, AdUrlLoadingListener listener)</a> <br> Handle ad engage event. SDK will call listener.shouldOverrideUrlLoading() for App while user engage and you can decide to open device's default browser or do other thing you want.</p> |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#setAudienceTargetingTags">setAudienceTargetingTags(Context context, List tagList)</a> <br> Set audience tags for targeting.</p>                                                                                                                                                                   |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#setDownloadTrafficListener">setDownloadTrafficListener(Context context, DownloadTrafficListener listener)</a> <br> To report the download size to App.</p>                                                                                                                                        |
| void           | <p><a href="/crystalexpress-documentation-v3-x/android-sdk/api-reference/i2wapi.md#setMaximumBitmapCacheSize">setMaximumBitmapCacheSize(Context context, int maximumBitmapCacheSize)</a> <br> Set the maximum bitmap size for cache.</p>                                                                                                                                             |

## Public methods

### blockAd <a href="#blockad" id="blockad"></a>

void blockAd(Context context, Ad ad, int reason, String description)

Block an ad.

| Parameters  |                                                                                                                                                                               |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| context     | Context: the context.                                                                                                                                                         |
| ad          | [Ad](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/1/README.md): the ad you want to block. |
| reason      | int: the reason code. 1 : not relevant, 2 : see the same ad too often, 3 : inappropriate                                                                                      |
| description | String: the description.                                                                                                                                                      |

### getAdditionalInfo <a href="#getadditionalinfo" id="getadditionalinfo"></a>

JSONObject getAdditionalInfo(Context context)

Get SDK additional info. such as device id, SDK version etc.

| Parameters |                       |
| ---------- | --------------------- |
| context    | Context: the context. |

| Returns    |                      |
| ---------- | -------------------- |
| JSONObject | SDK additional info. |

void init(Context context)

### getAdsValidTime <a href="#getadditionalinfo" id="getadditionalinfo"></a>

List\<Long\[]> getAdsValidTime(Context context, String placement)

Get the ads valid time slot interval. Example: \[\[startTime, endTime], \[startTime, endTime] ....]

| Parameters |                        |
| ---------- | ---------------------- |
| context    | Context: the context.  |
| placement  | String: the placement. |

| Returns        |                                  |
| -------------- | -------------------------------- |
| List\<Long\[]> | return the valid ads time array. |

### init <a href="#init1" id="init1"></a>

Initialize sdk.

| Parameters |                       |
| ---------- | --------------------- |
| context    | Context: the context. |

### init <a href="#init2" id="init2"></a>

void init(Context context, boolean isTestAd)

Initialize sdk.

| Parameters |                                                                                                                                                                                     |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| context    | Context: the context.                                                                                                                                                               |
| isTestAd   | <p>boolean: if SDK needs to fetch test ad for testing purpose or not. <br> <strong>APP should set this flag to "false" before deploying to the production environment</strong>.</p> |

### init <a href="#init3" id="init3"></a>

void init(Context context, boolean isTestAd, boolean isVerbose)

Initialize sdk.

| Parameters |                                                                                                                                                                                     |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| context    | Context: the context.                                                                                                                                                               |
| isTestAd   | <p>boolean: if SDK needs to fetch test ad for testing purpose or not. <br> <strong>APP should set this flag to "false" before deploying to the production environment</strong>.</p> |
| isVerbose  | <p>boolean: is print verbose log or not. <br> <strong>APP should set this flag to "false" before deploying to the production environment</strong>.</p>                              |

### onActivityResume <a href="#onactivityresume" id="onactivityresume"></a>

void onActivityResume(Context context)

Notify sdk that Activity has already in resume status.

| Parameters |                       |
| ---------- | --------------------- |
| context    | Context: the context. |

### onActivityPause <a href="#onactivitypause" id="onactivitypause"></a>

void onActivityPause(Context context)

Notify sdk that Activity has already in pause status.

| Parameters |                       |
| ---------- | --------------------- |
| context    | Context: the context. |

### preload <a href="#preload" id="preload"></a>

void preload(Context context, String placement)

Notify the SDK to preload this placement.

| Parameters |                                            |
| ---------- | ------------------------------------------ |
| context    | Context: the context.                      |
| placement  | String: the placement you want to preload. |

### preload <a href="#preload2" id="preload2"></a>

void preload(Context context, RequestInfo requestInfo)

Notify the SDK to preload by RequestInfo

| Parameters  |                                                                                                                                                                                                      |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| context     | Context: the context.                                                                                                                                                                                |
| requestInfo | [RequestInfo](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/requestinfo.html): the placement you want to preload. |

### hasReadyAd <a href="#hasreadyad" id="hasreadyad"></a>

boolean hasReadyAd(Context context, String placement)

Check is there any ready ad at this moment

| Parameters |                                          |
| ---------- | ---------------------------------------- |
| context    | Context: the context.                    |
| placement  | String: the placement you want to check. |

| Returns |                                                                |
| ------- | -------------------------------------------------------------- |
| boolean | return true if there is at least one ready ad, otherwise false |

### setAdUrlLoadingListener <a href="#setadurlloadinglistener" id="setadurlloadinglistener"></a>

void setAdUrlLoadingListener(Context context, [AdUrlLoadingListener](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/adurlloadinglistener.html) listener)

Handle ad engage event. SDK will call listener.shouldOverrideUrlLoading() for App while user engage and you can decide to open device's default browser or do other thing you want.

| Parameters |                                                                                                                                                                                                                                                                                           |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| context    | Context: the context.                                                                                                                                                                                                                                                                     |
| listener   | [AdUrlLoadingListener](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/adurlloadinglistener.html): the listener will be saved as WeakReference in the SDK, so App should maintain this listener by self. |

### setAudienceTargetingTags <a href="#setaudiencetargetingtags" id="setaudiencetargetingtags"></a>

void setAudienceTargetingTags(Context context, List\<String> tagList)

Set audience tags for targeting.

| Parameters |                                        |
| ---------- | -------------------------------------- |
| context    | Context: the context.                  |
| tagList    | List\<String>: all tags for targeting. |

### setDownloadTrafficListener <a href="#setdownloadtrafficlistener" id="setdownloadtrafficlistener"></a>

void setDownloadTrafficListener(Context context, [DownloadTrafficListener](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/downloadtrafficlistener.html) listener)

To report the download size to App.

| Parameters |                                                                                                                                                                                                                                                                                                 |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| context    | Context: the context.                                                                                                                                                                                                                                                                           |
| listener   | [DownloadTrafficListener](https://github.com/intowow/crystalexpress-documentation-v3-x/tree/eea8a8ed348d77ae2fac3bcbe123fc19fcc36f5c/android/api_reference/downloadtrafficlistener.html): the listener will be saved as WeakReference in the SDK, so App should maintain this listener by self. |

### setMaximumBitmapCacheSize <a href="#setmaximumbitmapcachesize" id="setmaximumbitmapcachesize"></a>

void setMaximumBitmapCacheSize(Context context, int maximumBitmapCacheSize)

Set the maximum bitmap size for cache.

| Parameters             |                                         |
| ---------------------- | --------------------------------------- |
| context                | Context: the context.                   |
| maximumBitmapCacheSize | int: the maximum bitmap size for cache. |
