# Setting MPM SDK

IMQA MPM offers various options and enables the user to add custom settings for generating more detailed crash reports.

## 1. MPM installation options <a href="#mpm" id="mpm"></a>

### MPM option files <a href="#file" id="file"></a>

You can manage settings using the settings file for IMQA. Those files should be placed at the app level.

{% code title="(project root)/(app)/imqa-service.json" %}

```json
{
  "stop" : true,
  "mpm" : false,
  "crash" : true,
  "core" : true,
  "repackaging" : false,
  "lifecycle" : true,
  "event_listener" : true,
  "library_activity" : true,
  "fragment_lifecycle" : true,
  "webview" : true,
  "network" : true,
  "build_location" : "",
  "flavor" : "",
  "manifest_location" : "",
  "mapping_upload" : true,
  "map_upload_server" : "",
  "project_key" : "IMQA_KEY",
  "runtime" : {
    "buildType" : false,
    "printLog" : true,
    "dump_interval" : 1000,
    "file_interval" : 5,
    "upload_period" : true,
    "network_collect" : true,
    "socket_tracing" : false,
    "http_tracing" : true,
    "keep_file_on_fail" : true,
    "force_https" : false,
    "end_date" : "",
    "os_version_limit_list" : [],
    "app_version_limit_list" : [],
    "dump_size_max" : 10,
    "behavior_max" : 100
  }
}
```

{% endcode %}

### Description of file build setting values <a href="#option-name" id="option-name"></a>

<table><thead><tr><th width="198" align="center">Option Name</th><th width="145.92502258355918" align="center">Default Value</th><th width="406.2">Description</th></tr></thead><tbody><tr><td align="center">stop</td><td align="center">false</td><td>Executes all injecting processes of MPM. All execution processes are ignored if set as \n true.</td></tr><tr><td align="center">mpm</td><td align="center">true</td><td>Installs an SDK for MPM. The MPM library cannot be used if set to false.</td></tr><tr><td align="center">crash</td><td align="center">true</td><td>Installs an SDK for Crash. The Crash library cannot be used if set to false.</td></tr><tr><td align="center">core</td><td align="center">true</td><td>Installs the IMQA Core SDK. The Core library cannot be used if set to false.</td></tr><tr><td align="center">repackaging</td><td align="center">true</td><td>Sets repackaging mode. Injection is performed during compilation if set to false.</td></tr><tr><td align="center">lifecycle</td><td align="center">true</td><td>Allows activity lifecycle injecting. The activity map is hidden if set to false.</td></tr><tr><td align="center">event_listener</td><td align="center">true</td><td>Allows event listener injecting. Event information is not collected if set to false.</td></tr><tr><td align="center">fragment_lifecycle</td><td align="center">true</td><td>Sets whether to collect fragments or not. The rendering speed of the fragment is not collected if set to false.</td></tr><tr><td align="center">webview</td><td align="center">true</td><td>Allows WebView related injecting. HTTP/S requests in the WebView are not collected if set to false.</td></tr><tr><td align="center">network</td><td align="center">true</td><td>Wraps the network collection method. Network-related response speed is not collected if set to false.</td></tr><tr><td align="center">manifest_location</td><td align="center">""</td><td>You can manually set the manifest location of the current build environment. The plugin automatically searches if not set.</td></tr><tr><td align="center">flavor</td><td align="center">""</td><td>You can manually set the flavor of the current build environment. The plugin automatically searches if not set.</td></tr><tr><td align="center">mapping_upload</td><td align="center">true</td><td>Automatically uploads a mapping file when it is created.</td></tr><tr><td align="center">map_upload_server</td><td align="center">"http://mpm.imqa.io"</td><td>Wraps the network collection method. Network-related response speed is not collected if set to false.</td></tr><tr><td align="center">project_key</td><td align="center">""</td><td>Sets the project key for the current app. Additional setting is required to upload the “mapping.txt” file properly. An upload failure message may appear in the build log if not set.</td></tr></tbody></table>

### Description of file runtime setting values <a href="#runtime" id="runtime"></a>

<table><thead><tr><th width="211.24966622162881" align="center">Option Name</th><th width="145" align="center">Default Value</th><th width="390.2">Description</th></tr></thead><tbody><tr><td align="center">buildType</td><td align="center">false</td><td><p>Sets whether IMQA collects data.</p><p>- true: Do not collect data.</p><p>- false: Collects data.</p></td></tr><tr><td align="center">printLog</td><td align="center">false</td><td>Sets whether to output the log. Outputs IMQA logs if set to true.</td></tr><tr><td align="center">dump_interval</td><td align="center">5000</td><td>Sets the dump interval in ms (milliseconds).</td></tr><tr><td align="center">file_interval</td><td align="center">5</td><td>Sets the interval of saving dumps in a file in minutes.</td></tr><tr><td align="center">upload_period</td><td align="center">false</td><td>Sets whether to upload a file periodically. Uploads a file according to the FileInterval while the app is running. Uploads collected data while executing the app again only if set to false.</td></tr><tr><td align="center">socket_tracing</td><td align="center">true</td><td>Sets the function of collecting information related to the socket. Collects and saves network communication information using the socket while the app is running, if set to true.</td></tr><tr><td align="center">http_tracing</td><td align="center">true</td><td>Sets the function of collecting HTTP related information. Collects and saves HTTP information while the app is running, if set to true.</td></tr><tr><td align="center">keep_file_on_fail</td><td align="center">true</td><td>Sets whether to leave the measured performance file until upload is successful. Keeps the file inside until the upload is successful. If set to false, the file is deleted even if upload fails.</td></tr><tr><td align="center">mpm_server_url</td><td align="center"><a href="http://collector.imqa.io">http://collector.imqa.io</a></td><td>Sets the URL of the MPM server.</td></tr><tr><td align="center">force_https</td><td align="center">false</td><td>Establishes HTTPS communication by ignoring the certificate (SSL) of the upload server if set to false.</td></tr><tr><td align="center">end_date</td><td align="center">(none)</td><td>Sets the end date.</td></tr><tr><td align="center">os_version_limit_list</td><td align="center">[]</td><td>Sets the OS version to run.</td></tr><tr><td align="center">app_version_limit_list</td><td align="center">[]</td><td>Sets the app version to run.</td></tr><tr><td align="center">dump_size_max</td><td align="center">10</td><td>Sets the maximum usage of dump data. (in MB)</td></tr><tr><td align="center">behavior_max</td><td align="center">15</td><td>Sets the maximum number of behavior analysis data.</td></tr></tbody></table>

### **Gradle File** <a href="#gradle" id="gradle"></a>

You can change the IMQA MPM installation mode using gradle.

{% code title="app.gradle" %}

```java
ext {
    /**
     * @Default false
     * Executes all injecting processes of MPM. 
     * All execution processes are ignored if set to true.
     */
    IMQAStop = false

    /**
     * @Default true
     * Allows activity lifecycle injecting. 
     * The activity map is hidden if set to false.
     */
    IMQALifecycle = true

    /**
     * @Default true
     * Allows event listener injecting.
     * Event information is not collected if set to false.
     */
    IMQAEventListener = true

    /**
     * @Default false
     * Allows injecting related to WebView.
     * HTTP/S requests in the WebView are not collected if set to false.
     */
    IMQAWebview = false

    /**
     * @Default true
     * Sets whether to collect fragments or not.
     * The rendering speed of the fragment is not collected if set to false.
     */
    IMQAFragment = true

    /**
     * @Default true
     * Wraps the network collection method.
     * Network-related response speed is not collected if set to false.
     */
    IMQANetwork = true

    /**
     * @Default ""
     * You can manually set the flavor of the current build environment.
     * The plugin automatically searches if not set.
     */
    IMQAFlavor = "debug";

    /**
     * @Default "/build/intermediates/manifests/full/"
     * You can manually set the manifest location of the current build environment.
     * The plugin automatically searches if not set.
     */
    IMQAManifestLocation = "/build/intermediates/manifests/full/"

    /**
     * @Default true
     * Sets repackaging mode.
     * Injection is performed during compilation if set to false.
     */
    IMQARepackaging = false

    /**
     * @Default true
     * Automatically uploads a mapping file when it is created.
     * If not set, “mapping.txt” for each app version should be uploaded by connecting to IMQA.
     */
    IMQAMappingUpload = true

    /**
     * @Default ""
     * Sets the project key for the current app.
     * Additional setting is required to upload the “mapping.txt” file properly.
     * An upload failure message may appear in the build log if not set.
     */
    IMQAProjectKey = "";

    /**
     * @Default "http://mpm.imqa.io"
     * Input the host name to upload the “mapping.txt” file.
     * Additional setting is required to upload the “mapping.txt” file properly.
     * An upload failure message may appear in the build log if not set.
     */
    IMQAMapUploadServer = "http://mpm.imqa.io"

}
```

{% endcode %}

### MPM Run Option <a href="#run-option" id="run-option"></a>

You can change the IMQA MPM mode using parameters or options.

{% code title="MyApplication.java" %}

```java
@Override
public void onCreate() {
    super.onCreate();
    
    io.imqa.core.IMQAOption imqaOption = new io.imqa.core.IMQAOption();

    /*
     *  Default value: true 
     *  Sets execution mode. 
     *  true: Runs in release mode only.
     *  false: Runs in debug mode only. 
    */
    imqaOption.setBuildType(false);

    /*
     * Default value: false
     * Sets whether to output the log. 
     * true: Outputs the IMQA log.
    */
    imqaOption.setPrintLog(true);

    /*
     * Default value: 5000 (ms)
     * Sets the dump interval in ms (milliseconds).

    */
    imqaOption.setDumpInterval(3000);

    /*
     * Default value: 5 (minutes).
     * Sets the interval of saving dumps in a file in minutes.
    */
    imqaOption.setFileInterval(1);

    /*
     * Default value: false
     * Sets whether to upload a file periodically.
     * true: Uploads a file according to the FileInterval while the app is running.
     * false: Uploads collected data while executing the app again.
    */
    imqaOption.setUploadPeriod(true);

    /*
     * Deprecated
     * Default value: true
     * Sets the function of collecting information related to the socket.
     * true: Collects and saves network communication information using the socket while the app is running.
     * false: The IMQA socket collection function is not set.
    */
    imqaOption.setNetworkTracing(false);

    /*
     * Default value: true
     * Sets the function of collecting information related to the socket.
     * true: Collects and saves network communication information using the socket while the app is running.
     * false: The IMQA socket collection function is not set.
    */
    imqaOption.setSocketTracing(false);

    /*
     * Default value: true
     * Sets the function of collecting HTTP related information.
     * true: Collects and saves HTTP information while the app is running.
     * false: The IMQA HTTP collection function is not set.
    */
    imqaOption.setHttpTracing(false);

    /*
     * Default value: true
     * Sets whether to leave the measured performance file until upload is successful.
     * true: Keeps the file inside until the upload is successful.
     * false: The file is deleted even if upload fails.
    */
    imqaOption.setKeepFileAtUploadFail(false);

    /*
     * Default value: false
     * Establishes HTTPS communication by ignoring the certificate (SSL) of the upload server.
     * true: Ignores the certificate and establishes HTTPS communication.
     * false: Checks the certificate and establishes HTTPS communication.
     */
    imqaOption.setForceHttps(true);

    /*
     * Default value : null
     * Sets the end date.
     * Date: End date
     */
    imqaOption.setEndDate(Date);

    /*
     * Default value : false
     * Gets option settings from the server. Requests to the collection server set with setServerUrl.
     * Sets as the highest priority option. If not responded, it will be operated with the option set in the code.
     * true: Gets options from the server.
     * false: Operates with the option set in the code.
     */
    imqaOption.setRemoteConfig(true);

    /*
     * Default value : 3000
     * Sets a time-out when getting remote server options.
     * When a time-out occurs, it operates with the option set in the code.
     * int : timeout (ms)
     */
    imqaOption.setRemoteTimeout(3000);

    /*
     * 기본값 : ArrayList<Integer>
     * Sets the OS version to run.
     * int : Running OS version
     */
    imqaOption.addOSVersionLimitList(Build.VERSION_CODES.O);

    /*
     * Default value : OSProhibit
     * Does not activate the SDK under the version in question.
     * int : Running OS version
     */
    imqaOption.getOSProhibitVersionLimitList().addOSProhibitVersionLimitBelow(Build.VERSION_CODES.M);

    /*
     * Default value : ArrayList<String>
     * Sets the app version to run.
     * String : Running app version
     */
    imqaOption.addAppVersionLimitList("1.1");


    /*
     * Default value : null
     * Specifies the URL that will be excluded from collection.
     * By default, host and pathname will apply. Query value match can be added as an option.
     * String : Target url
     * boolean : query matching status (e.g.,: After the question mark (?) in https://abc.com/search?foo=bar)
     */
    imqaOption.getURLBlacklist().addBlacklistURL("https://abc.com/search", false);

    /*
     * Default value : ArrayList<AccessPoint>
     * Sets the app version to run.
     * One AP for each AccessPoint object. If no unique value is set among three options, it will be deemed true.
     * As SSID and BSSID require location authority,
     * “ACCESS_FINE_LOCATION” or “ACCESS_COARSE_LOCATION” should be added to use this authority.
     * AccessPoint: Active SSID, BSSID, IP
     */
    io.imqa.core.network.AccessPoint ap = new io.imqa.core.network.AccessPoint();
    ap.setSsid("IMQA");
    ap.setBssid("cc:40:d0:f7:a5:d7");
    ap.setIpAddress("192.168.0.1");
    imqaOption.addWifiLimitList(ap);

    /*
     * Default value : 10
     * Sets the maximum usage of dump data.
     * int : Maximum usage (in MB)
     */
    imqaOption.setDumpSizeMax(10);

    /*
     * Default value : 15
     * Sets the maximum number of behavior analysis data.
     * int: maximum count
     */
    imqaOption.setBehaviorLengthMax(15);

    /*
     * Default value : 'IMQA-ADDITIONAL-KEY'
     * Inputs additional header information when establishing HTTP communication.
     * String: Name of the additional header key
     */
    imqaOption.setAdditionalHeader(true, "MY-HEADER");
    // 또는
    imqaOption.setAdditionalHeader(true);
    imqaOption.setAdditionalHeaderKey("MY-HEADER");
    
    io.imqa.mpm.IMQAMpmAgent.getInstance()
        .setOption(imqaOption) // Sets the option to decide the MPM operation method.
        .setContext(this, BuildConfig.FLAVOR) // Initializes the application context.
        .setProjectKey("PROJECT_KEY") // Sets the project key of the IMQA MPM client.
        .init() // Initializes the registered options.
```

{% endcode %}

### Executing independent MPM <a href="#injector" id="injector"></a>

You can execute IMQA MPM Injector in a specific task. However, if you use the above method, codes may not be inserted normally depending on the executed location.

{% code title="app.gradle" %}

```gradle
// apply plugin: 'io.imqa' // Should be deactivated for independent execution.

// You must manually insert this part because auto-insert function is canceled.
dependencies {
       implementation 'io.imqa:imqa-core:2.27.5'
       implementation 'io.imqa:imqa-mpm-client:2.27.9'
       implementation 'io.imqa:imqa-crash-client:2.27.5'
 }

// Creates with a constructor because it is a plugin object (uses static internally.)
io.imqa.IMQAPlugin imqaPlugin = new io.imqa.IMQAPlugin()
// Sets basic IMQA options (IMQAOption, BuildOption, imqa-service.json.)
imqaPlugin.init(project)

// Creates with a constructor because it is an action object (uses static internally.)
// Reflects IMQA options in app.gradle. Reflects the basic information of the development environment (build tool, variants, etc.). Inserts IMQA dependency automatically.
new io.imqa.injector.GJavacAction(project.name).setConfiguration(project)

android.applicationVariants.all { variant ->
    // A variable name must be inserted into doLast Lamda when setting.
    // If the variable name is not specified, an error occurs because the built-in gradle “task” is called.
    variant.javaCompile.doLast { task ->
        // Executes CompileAction at the current location based on the above settings.

        // If there are Kotlin codes in the project, add the codes below:
        new io.imqa.injector.CompileAction(
                io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.kotlin,
                project.name,
                io.imqa.injector.GJavacAction.convertBuildType(variant.getBuildType()),
                io.imqa.injector.GJavacAction.makeFlavor(variant.getBuildType().name,   variant)
            )
            .execute(task)

        // Gradle 3.2 ~ 3.4, 4.0, 4.1 :  io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.javacCompileClasses

       // Gradle 3.5 and later  io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.javacClasses

       // Other versions: io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.classes

        new io.imqa.injector.CompileAction(
                io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.javacCompileClasses,
                project.name,
                io.imqa.injector.GJavacAction.convertBuildType(variant.getBuildType()),
                io.imqa.injector.GJavacAction.makeFlavor(variant.getBuildType().name,   variant)
            )
            .execute(task)
    }
}
```

{% endcode %}

### Setting network collection

The IMQA MPM framework automatically measures network collection, but for specific libraries, manual settings must be made.

#### Responding to AsyncHttpClient

When requesting a network using the AsyncHttpClient library, please add the following.

{% code title="MainActivity.java" %}

```javascript
...
AsyncHttpClient client = new AsyncHttpClient();
...
HttpData httpData = new HttpData();
client.get(this, url, new AsyncHttpResponseHandler() {
    @Override
    public void onStart() {
       // Enter network request information
        URI uri = this.getRequestURI();
        httpData.setHostName(uri.getHost());
        httpData.setMethod("get"); // get | post 
        httpData.setProtocol(uri.getScheme());
        httpData.setPathName(uri.getPath());
    }
    @Override
    public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
          // Enter network response code ( if successful ) 
           httpData.setStatus(statusCode + "");
    }
    @Override
    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
          // Enter network response code ( if failure ) 
        httpData.setStatus(statusCode + "");
    }
    @Override
    public void onFinish() {
        // Network collection progress ( Upon completion of request ) 
        httpData.setEndTime(System.currentTimeMillis());
        HttpCollector.collect(httpData);
    }
});

...
```

{% endcode %}

## &#x20;<a href="#proguard" id="proguard"></a>

## 2. Setting ProGuard <a href="#proguard" id="proguard"></a>

ProGuard is a tool used to make the APK as small as possible in size by removing unused resources and shortening the name of classes or methods. When using ProGuard or DexGuard, the original class and method name can be displayed on the crash report by uploading the mapping file as below:

### Preparation <a href="#preparation" id="preparation"></a>

If ProGuard is used in a project under development, the source code is obfuscated, making the analysis difficult. In this case, obfuscated codes can be analyzed using the generated mapping.txt file.

Add the following to ProGuard rules (proguard-rules.pro):

{% code title=" proguard-rules.pro" %}

```
 -keepattributes SourceFile,LineNumberTable
 -printmapping map.txt

 # IMQA Proguard
 -keep class io.imqa.** { *; }
 -dontwarn io.imqa.**

 # okhttp3 Proguard
 -dontwarn okhttp3.**
 -dontwarn okio.**oj
```

{% endcode %}

A file is created in the app/build/outputs/mapping/debug (or release)/mapping.txt directory. (The file location may differ a little depending on the buildType and flavor.)\
You need to connect to <http://crash.imqa.io> to upload the file created in this way.

{% hint style="warning" %}
When uploading the file, its name must be named as “mapping.txt” or “map.txt”.
{% endhint %}

### Upload process <a href="#upload" id="upload"></a>

1\. Select “Setting” at the project menu.

<figure><img src="https://lh7-us.googleusercontent.com/ltVGJqi1fzxBqmLWsQA_4XtciN5fZKdRNM9me6X55SwuFJA3VryytnWVs88WOGKoTs8gD6eZixz0nK3ComAzjqmHjUlgnau6ETzk_u6vMJTO5Zl0lqzz30u70nN7jwqnGZSLbl2JfwCcI8eGFBExrw" alt=""><figcaption></figcaption></figure>

2\. Click the \[File Upload] button to open the upload window.

<figure><img src="https://lh7-us.googleusercontent.com/w3s2aZJNvFqlSEykuQ3zorI_fbeQvB0wgUC1JWeHfCHVOu8LrwAf_MgDGNZJTabY3ouBHboNmmEpEfbIsaHAOEvsCHluosaieS00wLD6JiiGJ4AwLTXpZ9fWt5wYABRjsR512S89EXiMFtQSdnbM9w" alt=""><figcaption></figcaption></figure>

3\. Click the \[Choose File] button that matches the app version specified in the gradle and upload the “mapping.txt” file.

<figure><img src="https://lh7-us.googleusercontent.com/MWPCNfUJdK_hajkzh1XzD7JnEDwiGVi4q_6jjMIemoEXCQ7Ev8ROhVlLr9YFjx6pxUhAugOS_t5IiP6aLj9UCXKUV5U3QhI2CWDagPTHburscsY9LSdKIANqhMLEgh83d6zU6w6UIo3Q6FmduJkdbA" alt=""><figcaption></figcaption></figure>

4\. If you click the \[Upload] button, the crash information collected afterwards will be displayed after analysis.

{% hint style="warning" %}
**When the latest version of the app is released,** please register additional mapping files of the same app version in order to view the version’s crash information.
{% endhint %}

## 3. **MPM Webview Guide** <a href="#mpm-webview-guide" id="mpm-webview-guide"></a>

### **WebView HTTP** request <a href="#webview-http" id="webview-http"></a>

#### Setting the web server <a href="#web-server" id="web-server"></a>

To collect WebView data, the IMQA Webview JavaScript library should be inserted into the web page that provides WebView. If you wish, you can also download the file and share it via web server.

(It is recommended to directly import and use this if a Cross-Origin Resource Sharing (CORS) problem occurs.)

{% hint style="info" %}
For information on how to install the Agent when using MPM / WPM integration, refer to ‘IMQA WPM/WCrash Installation Guide > 1.2. Please refer to 'Using WPM / MPM integration (Installing WebAgent + WebviewAgent)'.
{% endhint %}

{% code title="Inserting a WebView file" %}

```javascript
<!-- IMQA Webview Agent(ver. 1.1.3 earlier)  -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.2.js"
crossorigin></script>

<!-- If you want to apply it as a min file: -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.2.min.js"
crossorigin></script>
```

{% endcode %}

```html
<!-- IMQA Webview Agent (ver. 1.1.3 later) -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.3.js"
crossorigin></script>

<script>
    ((w, c, _wv, _w, _wk, _mh, _b) => {        
       w[_wv](w); // Webview Agent Execution Function
    })(window, 'imqaClientConfig', 'IMQAWebviewMain', 'IMQAWebMain', 'webkit', 'messageHandlers', 'ImqaBridge')
</script>
```

#### Android Agent Setup <a href="#android-agent" id="android-agent"></a>

MPM collects WebView-related pages and requests. To enable the collection, you need to set up options and add MPMWebviewInterface. Additionally, error information occurring in WebView can be collected. To collect Webview Crash, you must add CrashWebviewBridge.

{% code title="MyWebViewActivity.java" %}

```java
...
public void onCreate() {
    WebView webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true); // Javascript Enable

    // Insert WebView interface (ImqaBridge required)
    io.imqa.mpm.network.webview.WebviewInterface imqaJavascript = 
        new io.imqa.mpm.network.webview.WebviewInterface();

    // Additional setup code (Webview Agent (ver. 1.1.2 later) WebView Crash Collection)
    imqaJavascript.setSendErrorBridge(new io.imqa.crash.webview.CrashWebviewBridge(this));

    webView.addJavascriptInterface(imqaJavascript, "ImqaBridge");
    ...
    }
...
```

{% endcode %}

{% code title="MyWebViewActivity.kt" %}

```kotlin
...
public void onCreate() {
    // IMQA settings section
    val webview:WebView = findViewById(R.id.webview_sample)
    webview.settings.javaScriptEnabled = true; // Javascript Enable

    // Insert WebView interface (ImqaBridge required)
    val imqaJavascriptInterface:io.imqa.mpm.network.webview.WebviewInterface = io.imqa.mpm.network.webview.WebviewInterface();

    // Additional setup code (Webview Agent (ver. 1.1.2 later) WebView Crash Collection)
    imqaJavascriptInterface.setSendErrorBridge(CrashWebviewBridge(this))

    webview.addJavascriptInterface(imqaJavascriptInterface,"ImqaBridge")	
    ...
    }
...   
```

{% endcode %}

## **4. MPM HTTPS Guide** <a href="#mpm-https-guide" id="mpm-https-guide"></a>

### Responding to HttpsURLConnection <a href="#url-connection" id="url-connection"></a>

IMQA Client can collect HttpsURLConnection based network requests. Add the following when requesting an HttpsURLConnection based network.

#### **HttpsURLConnection** <a href="#connection" id="connection"></a>

{% code title="MainActivity.java" %}

```java
...
// Wraps the HttpsURLConnection object with ConnectionWrapper.
URL url = new URL("https://some.host.com");
HttpsURLConnection conn = (HttpsURLConnection) ConnectionWrapper.wrap((HttpsURLConnection) url.openConnection());
...
```

{% endcode %}

{% code title="MainActivity.kt" %}

```java
...
// Wraps the HttpsURLConnection object with ConnectionWrapper.
var url : URL = URL("https://some.host.com")
var conn : HttpsURLConnection = 
    ConnectionWrapper.wrap(
        url.openConnection() as HttpsURLConnection
    ) as HttpsURLConnection
...
```

{% endcode %}

### Responding to OkHttp <a href="#okhttp" id="okhttp"></a>

IMQA Client can collect OkHttp based network requests. Add the following when requesting an OkHttp based network.

#### **OkHttp Client** <a href="#okhttp-client" id="okhttp-client"></a>

**1. OkHttp3**

{% code title="MainActivity.java" %}

```java
...
// Add MPMInterceptor to OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
    .addNetworkInterceptor(new MPMInterceptor())
    .build();
...

// Run OkHttpClient with the added interceptor
Response response = client.newCall(request).execute();
...
```

{% endcode %}

{% code title="MainActivity.kt" %}

```java
...
// Add MPMInterceptor to OkHttpClient
val builder : OkHttpClient.Builder = OkHttpClient.Builder()
val client : OkHttpClient = IMQAManager.wrapOkhttp(builder)
    .addNetworkInterceptor(MPMInterceptor())
    .build();
...

// Run OkHttpClient with the added interceptor.
val response : Response = client.newCall(request).execute()
...
```

{% endcode %}

**2. Retrofit 2.0**

{% code title="MainActivity.java" %}

```java
...
// Add MPMInterceptor to OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
    .addNetworkInterceptor(new MPMInterceptor())
    .build();
...

new Retrofit.Builder()
    .baseUrl(host)
    .client(client) // Use OkHttpClient with the added interceptor
    .build();
...
```

{% endcode %}

{% code title="MainActivity.kt" %}

```java
...
// Add MPMInterceptor to OkHttpClient
val builder : OkHttpClient.Builder = OkHttpClient.Builder()
val client : OkHttpClient = IMQAManager.wrapOkhttp(builder)
    .addNetworkInterceptor(MPMInterceptor())
    .build();
...

val retrofit = Retrofit.Builder()
    .baseUrl(host)
    .client(client) // Use OkHttpClient with the added interceptor
    .build()
...
```

{% endcode %}

#### Responding to the image loading library <a href="#image-loading" id="image-loading"></a>

**1. Picasso**

For Picasso, OkHttp is selected as a default downloader when using OkHttp. Add the following to add an interceptor to this downloader. First, add OkHttp3Downloader dependency.

```css
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
```

{% code title="MainActivity.java" %}

```java
// The downloader that MPMInterceptor is added in advance should be inserted before initializing Picasso's Singleton instance.
Picasso.setSingletonInstance(
    new Picasso.Builder(this)
            .downloader(new OkHttp3Downloader(
                    new OkHttpClient.Builder()
                            .addInterceptor(new MPMInterceptor())
                            .build()
            )).build());
```

{% endcode %}

**2. Glide**

For Glide, HttpUrlConnection is used as the default HTTP library. Set OkHttpClient in the registry to use OkHttp.

```java
compile "com.github.bumptech.glide:okhttp3-integration:4.8.0"
```

{% code title="MainActivity.java" %}

```java
@GlideModule
public class MyAppGlideModule extends AppGlideModule {

    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        super.registerComponents(context, glide, registry);
        OkHttpClient client = new OkHttpClient.Builder()
                .addNetworkInterceptor(new MPMInterceptor())
                .build();
        registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
    }
    ...
}
```

{% endcode %}

### Responding to HttpClient <a href="#http-client" id="http-client"></a>

IMQA Client can collect HttpClient based network requests. Add the following when requesting an HttpClient based network.

#### **HttpClient**

**1. HttpClient (org.apache.http.legacy)**

{% code title="MainActivity.java" %}

```java
...
// Add HttpClientInterceptor to DefaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpClientInterceptor.setIMQAInterceptor(httpClient);
...
```

{% endcode %}

{% code title="MainActivity.kt" %}

```java
...
// Add HttpClientInterceptor to DefaultHttpClient
val httpClient : DefaultHttpClient = DefaultHttpClient()
HttpClientInterceptor.setIMQAInterceptor(httpClient)
...
```

{% endcode %}

**2. HttpClient (cz.msebera.android.httpclient)**

{% code title="MainActivity.java" %}

```java
...
// Add OldHttpClientInterceptor to DefaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
OldHttpClientInterceptor.setIMQAInterceptor(httpClient);
...
```

{% endcode %}

{% code title="MainActivity.kt" %}

```java
...
// Add HttpClientInterceptor to DefaultHttpClient
val httpClient : DefaultHttpClient = DefaultHttpClient()
OldHttpClientInterceptor.setIMQAInterceptor(httpClient)
...
```

{% endcode %}

### Responding to Volley <a href="#volley" id="volley"></a>

IMQA Client can collect Volley based network requests. Add the following when requesting a Volley based network.

#### **Volley**

**1. Volley (com.android.volley)**

{% code title="MainActivity.java" %}

```java
...


StringRequest request = new StringRequest(
   ....
)

// Add IMQAHurlStack to RequestQueue
RequestQueue requestQueue = Volley.newRequestQueue(this, new IMQAHurlStack());
requestQueue.add(request);
...
```

{% endcode %}

### Issues in the current version <a href="#issue" id="issue"></a>

{% hint style="warning" %}
The Interceptor function should be manually inserted.

(Currently, automatic installation of HTTPUrlConnection, OkHttp, Retrofit, and HttpClient (org.apache, cz.msebera) is supported.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.imqa.io/imqa-guide/eng/installation-guide/android/mpm-sdk-setting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
