---
updatedAt: 2025-12-30T10:18:24.000Z
agentTools:
  projectIndex: https://docs.credolab.com/llms.txt
---

# Android SDK Reference

## Class `CredoAppService.Builder`

`CredoAppService.Builder`  is responsible for creating the `CredoAppService` class instance

```kotlin
CredoAppService.Builder(context: Context)
```

#### Parameters:

| Name      | Description                                                                                           | Type                      |
| :-------- | :---------------------------------------------------------------------------------------------------- | :------------------------ |
| `context` | An instance of `Context` interface, which could provide information about an application environment. | `android.content.Context` |

<br />

### Method `CredoAppService.Builder.addModule(module: IModule)`

```kotlin
addModule(module: IModule) : CredoAppService.Builder
```

* The method adds a module to the builder configuration.

#### Parameters

| Name     | Description                                                      | Type      |
| :------- | :--------------------------------------------------------------- | :-------- |
| `module` | Requires one of the following [modules](https://docs.credolab.com/docs/android-sdk#modules) | `IModule` |

#### Returns

`CredoAppService.Builder`

<br />

### Method `CredoAppService.Builder.addPlugin(plugin: IPlugin<*>)`

```kotlin
addPlugin(plugin: IPlugin<*>) : CredoAppService.Builder
```

* The method adds a plugin to the builder configuration.

#### Parameters

| Name     | Description                                                      | Type     |
| :------- | :--------------------------------------------------------------- | :------- |
| `plugin` | Requires one of the following [plugins](https://docs.credolab.com/docs/android-sdk#plugins) | `IPugin` |

#### Returns

`CredoAppService.Builder`

<br />

### Method `CredoAppService.Builder.setIgnorePermissions(value)`

```kotlin
 setIgnorePermissions(value: Boolean) : CredoAppService.Builder
```

* The method will make`CredoAppService.collect() or execute()` methods to return an error if permissions aren't granted.
* The `true` value allows collecting dataset **even if not all permissions are granted**
* The `false` value prevents collecting dataset from running until all permissions are granted (including normal permissions).
* The default value is `true`.

#### Parameters

| Name    | Description                                | Type      |
| :------ | :----------------------------------------- | :-------- |
| `value` | Requires `Boolean` value `true` or `false` | `Boolean` |

#### Returns

`CredoAppService.Builder`

<br />

### Method `CredoAppService.Builder.build()`

```kotlin Kotlin
build() : CredoAppService
```

#### Returns

configured `CredoAppService` instance.

<br />

<br />

## Class `CredoAppService`

`CredoAppService` is responsible for capturing a client's digital footprint

<br />

### Method `CredoAppService.collect()`

```kotlin
collect() : CredoAppResult<String>
```

* Collects dataset and returns it locally. This method must not be called on the UI thread.
* Does not accept any parameters

#### Returns

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Type
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `CredoAppResult<String>`
      </td>

      <td>
        If the `collect` method is succeeded, returns the string, which represents the array of bytes that is encoded to the base64 string
      </td>
    </tr>

    <tr>
      <td>
        `CredoAppResult.Error`
      </td>

      <td>
        Returns an error if something goes wrong.
        Please refer to the error codes table.
      </td>
    </tr>
  </tbody>
</Table>

<br />

### Method `CredoAppService.getUngrantedPermissions()`

```kotlin Kotlin
getUngrantedPermissions(): CredoAppResult<Array<String>>
```

#### Returns

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Type
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `CredoAppResult<Array<String>>`
      </td>

      <td>
        Returns an array of ungranted permissions.
      </td>
    </tr>

    <tr>
      <td>
        `CredoAppResult.Error`
      </td>

      <td>
        Returns an error if something goes wrong.
        Please refer to the error codes table.
      </td>
    </tr>
  </tbody>
</Table>

<br />

## Class `CredoAppResult<T>.Success`

`CredoAppResult.Success` states for successful operation

**Fields:**

| Field Name | Type | Description                    |
| :--------- | :--- | :----------------------------- |
| `value`    | `T`  | Returns value of generic type. |

<br />

## Class`CredoAppResult.Error`

`CredoAppResult.Error` states for operation fail and contains error details

**Fields:**

| Field Name | Type     | Description                             |
| :--------- | :------- | :-------------------------------------- |
| `message`  | `String` | Returns the message value of the error. |
| `code`     | `Int`    | Returns the code value of the error     |

<br />

<br />

## Class `BehavioralModule`

```kotlin
BehavioralModule()
```

`BehavioralModule` is responsible for capturing a client's behavioral interaction with UI and OS

<br />

### Static method `BehavioralModule.startTracking()`

```kotlin
startTracking()
```

* Starts behavioral interaction metadata tracking

> 📘 When to invoke `startTracking()` ?
>
> Before version `3.0.0 <=` should be called as early as possible for instance, in desired activity `onCreate()` method. If you've version `>= 3.0.0` you can invoke `startTracking()` in any place in your code.

<br />

### Static method `BehavioralModule.stopTracking()`

```kotlin
stopTracking()
```

* Terminates behavioral metadata tracking

### Static method \` BehavioralModule.addPLugin(plugin: IBehavioralPlugin)

```
addPlugin(plugin: IBehavioralPlugin)
```

* Adds behavioral plugin to Behavioral Module

### Static method `BehavioralModule.setLogger(plugin: IPlugin<ILogger>)`

```kotlin
setLogger(plugin: IPlugin<ILogger>)
```

* Sets the [LoggingPlugin](https://docs.credolab.com/docs/android-sdk#logging-) to BehavioralModule

### Static method `BehavioralModule.init(context: Context)`

```kotlin
init(context: Context)
```

* Used to manually initialize the BehavioralModule in cases where auto-initialization is not available.
  See [Using Behavioral Module with Dynamic Feature](https://docs.credolab.com/update/docs/using-behavioral-module-with-dynamic-feature#/) for more details.

### How to use BehavioralModule

It is necessary to call the `BehavioralModule.startTracking()` method before proceeding to complete the application form. The example is below

```kotlin
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)         
        BehavioralModule.setLogger(LoggingPlugin()) // optional
        BehavioralModule.addPlugin(PhoneBehavioralPlugin()) // optional
        BehavioralModule.startTracking()
    }
}
```
```java Java
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BehavioralModule.setLogger(new LoggingPlugin()); // optional
        BehavioralModule.addPlugin(new PhoneBehavioralPlugin()); // optional
        BehavioralModule.startTracking();
    }
}
```
```kotlin Kotlin - Jetpack Compose
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            CredolabSdkAndroidTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Column(modifier = Modifier.testTag("root_column")) {
                        MainScreen("Credoapp SDK")
                    }
                }
            }
        }
        BehavioralModule.addPlugin(BehavioralPhonePlugin())
        BehavioralModule.startTracking()
    }
```

### Add screen tracking within Jetpack Compose app

```kotlin Kotlin
import credoapp.module.behavioral.tracker.credoAppTrackNavigation

val navController = rememberNavController().credoAppTrackNavigation()

NavHost(
  navController = navController
) {
  ...
}
```

Then pass `BehavioralModule` instance to `CredoAppService` to collect behavioral data along with other data

```kotlin
class SubmitActivity : AppCompatActivity() {
		// execute in background thread
    fun onSubmit() {
      val credoAppService = CredoAppService.Builder(applicationContext)
				// add other modules
        .addModule(BehavioralModule())
        .build()
      val result = credoAppService.collect()
      when (result) {
         is CredoAppResult.Success -> // send to the credolab server 
         is CredoAppResult.Error -> Log.d(TAG, "${result.message} ${result.code}")
      }
    }
}
```
```java Java
public class SubmitActivity extends AppCompatActivity {
   void onSubmit() {
    CredoAppService credoAppService = new CredoAppService.Builder(applicationContext)
            // add other modules
            .addModule(new BehavioralModule())
            .build();
    CredoAppResult result = credoAppService.collect();
    if (result instanceof CredoAppResult.Success) {
        // send to the credolab server
    } else if (result instanceof CredoAppResult.Error) {
        CredoAppResult.Error errorResult = (CredoAppResult.Error) result;
        Log.d(TAG, errorResult.getMessage() + " " + errorResult.getCode());
    }
 }
}
```

> 👍 Highly recommended
>
> **For successful integration,** we strongly recommend assigning a value to either the [ID](https://developer.android.com/reference/android/view/View#ids) or [Tag](https://developer.android.com/reference/android/view/View#tags~~) attributes or for Jetpack Compose app [testTag](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#\(androidx.compose.ui.Modifier\).testTag\(kotlin.String\)) modifier to emphasize a specific logical control or element that holds significance within the User Flow of your app.
>
> **For example:**
>
> ```xml XML
>  <Button
>   android:id="@+id/submit_button"
>   android:layout_width="wrap_content"
>   android:layout_height="wrap_content"
>   android:text="@string/submit_button"/>
> ```
> ```kotlin Jetpack Compose
>  Button(enabled = isUpload.not(), onClick = {
>         //....
>     }, modifier = Modifier.testTag("submit_btn")) {
>         Text("Submit")
>     }
> ```

> See more examples in our <Anchor label="Behavioral Module Identifiers Guide" target="_blank" href="https://docs.google.com/spreadsheets/d/1NrwazYZOcuCQZQiGT2rM-Pkdbub00FAfskvaUE8s7B0/edit?usp=sharing">Behavioral Module Identifiers Guide</Anchor> (Android)

<br />

### How to add Behavioral Plugins to Behavioral Module

```kotlin
BehavioralModule.addPlugin(PhoneBehavioralPlugin())
BehavioralModule.addPlugin(GuardBehavioralPlugin())
```
```java Java
BehavioralModule.addPlugin(new PhoneBehavioralPlugin());
BehavioralModule.addPlugin(new GuardBehavioralPlugin());
```

## Class `SmsIntelligenceModule`

```kotlin
SmsIntelligenceModule(securityParam)
```

`SmsIntelligenceModule` is responsible for extracting SMS metadata with hashed lexical patterns protected by security param set by client. **SecurityParam is required.**

#### Parameters

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Description
      </th>

      <th>
        Types
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `securityParam`
      </td>

      <td>
        A security parameter for hashing lexical patterns.
        Throws an exception if no security parameter (`SecurityParam.None`) is provided.
      </td>

      <td>
        `SecurityParam.Local`
        `SecurityParam.None` - Default parameter
      </td>
    </tr>
  </tbody>
</Table>

## Sealed Class `SecurityParam.Local`

**SecurityParam.Local** allows to provide a local custom salt (any non-empty string of your choice):

```
SecurityParam.Local(val salt: String)
```

This salt ensures secure, unique hashing of lexical patterns from users SMS content.

<Callout icon="❗️" theme="error">
  The `salt` must never change once data is uploaded to production environment!
</Callout>

<Callout icon="📘" theme="info">
  **SecurityParam is never sent to Credolab.**

  Hashing is performed entirely on the user's device using your custom salt. Only the hashed SMS metadata is uploaded. Without the salt, these hashes are cryptographically irreversible - even Credolab cannot recover the original SMS content.
</Callout>

#### Parameters

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Description
      </th>

      <th>
        Type
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `salt`
      </td>

      <td>
        A string value that is used in tokens hashing functions.
        Required.
      </td>

      <td>
        `String`
      </td>
    </tr>
  </tbody>
</Table>

<br />

## Error Codes

| Code | Reason                      | Description                                                                                                                                  |
| ---- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| 30   | Duplicated areas error      | The extracting areas are duplicated.                                                                                                         |
| 43   | Permissions are not granted | If setIgnorePermissions configured method with `false` boolean value, SDK prevents you from proceeding without all the necessary permissions |
| 90   | Unknown error               | An unexpected error occurred.                                                                                                                |