> For the complete documentation index, see [llms.txt](https://cramiumlabs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cramiumlabs.gitbook.io/docs/sdk-mpc-android/usage-guide-for-an-mpc-wallet-app/user-device-management-udm.md).

# User Device Management (UDM)

### Table of Contents

1. registerDevice
2. getLinkDevices
3. getLinkDevice
4. updateLastOnline
5. updateDeviceName
6. removeDevice
7. getLinkDevicesHistory

### Methods

#### registerDevice

Registers a new device with the system.

Parameters:

* `body`: A `RegisterDeviceRequest` object containing:
  * `uniqueId`: The unique identifier of the device
  * `uniqueIdType`: The type of unique identifier ( "uuid", "imei")
  * `label`: The device label
  * `type`: The device type ("mobile", "cloud", "browser")
  * `customName`: The custom name of the device
  * `os`: The operating system version
  * `browserName`: The browser name (if applicable)

```kotlin
fun registerDevice(context: Context, username: String) {
    viewModelScope.launch {
        passkey?.authenticate(username)
            ?.flatMapLatest {
                udmRepository = UDMRepositoryImpl("https://trust-fabric.mpc-dev.cramiumtech.com", it.accessToken)
                udmRepository!!.registerDevice(context)
            }
            ?.collect { response ->
                Log.d("MainActivityViewModel", "Register device response: $response")
            }
    }
}
```

#### getLinkDevices

Retrieves a list of all linked devices for the current user.

```kotlin
fun getLinkDevices() {
    viewModelScope.launch {
        udmRepository?.getLinkDevices()
            ?.collect { devices ->
                Log.d("MainActivityViewModel", "Link devices response: $devices")
            }
    }
}
```

#### getLinkDevice

Retrieves details of a specific linked device.

Parameters:

* `uniqueId`: The unique identifier of the device

```kotlin
fun getLinkDevice(uniqueId: String) {
    viewModelScope.launch {
        udmRepository?.getLinkDevice(uniqueId)
            ?.collect { device ->
                Log.d("MainActivityViewModel", "Link device response: $device")
            }
    }
}
```

#### updateLastOnline

Updates the last online timestamp for a specific device.

Parameters:

* `uniqueId`: The unique identifier of the device

```kotlin
fun updateLastOnline(uniqueId: String) {
    viewModelScope.launch {
        udmRepository?.updateLastOnline(uniqueId)
            ?.collect {
                Log.d("MainActivityViewModel", "Last online updated for device: $uniqueId")
            }
    }
}
```

#### updateDeviceName

Updates the display name of a specific device.

Parameters:

* `uniqueId`: The unique identifier of the device
* `name`: The new name for the device

```kotlin
fun updateDeviceName(uniqueId: String, name: String) {
    viewModelScope.launch {
        udmRepository?.updateDeviceName(uniqueId, name)
            ?.collect {
                Log.d("MainActivityViewModel", "Device name updated for device: $uniqueId")
            }
    }
}
```

#### removeDevice

Removes a device from the linked devices list.

Parameters:

* `uniqueId`: The unique identifier of the device

```kotlin
fun unlink(username: String) {
    viewModelScope.launch {
        passkey?.authenticate(username)
            ?.flatMapLatest {
                udmRepository = UDMRepositoryImpl("https://trust-fabric.mpc-dev.cramiumtech.com", it.accessToken)
                udmRepository!!.getLinkDevices()
            }
            ?.flatMapLatest { devices ->
                udmRepository!!.removeDevice(devices.last().uniqueId)
            }
            ?.collect {
                Log.d("MainActivityViewModel", "Device removed successfully")
            }
    }
}
```

#### getLinkDevicesHistory

Retrieves the history of device linking and unlinking events.

```kotlin
fun getLinkDevicesHistory() {
    viewModelScope.launch {
        udmRepository?.getLinkDevicesHistory()
            ?.collect { history ->
                Log.d("MainActivityViewModel", "Link devices history response: $history")
            }
    }
}
```

### Complete Example

Here's a complete example of how to use the UDM features:

```kotlin
// Initialize the repository
val udmRepository = UDMRepositoryImpl(
    baseUrl = "https://trust-fabric.mpc-dev.cramiumtech.com",
    accessToken = "your_access_token"
)

// Register a new device
viewModelScope.launch {
    udmRepository.registerDevice(
        RegisterDeviceRequest(
            uniqueId = context.getDeviceUuid(),
            uniqueIdType = "uuid",
            label = Build.DEVICE,
            type = "mobile",
            customName = Build.MODEL,
            os = Build.VERSION.RELEASE,
            browserName = "browser"
        )
    ).collect { device ->
        // Handle the registered device
    }
}

// Get all linked devices
viewModelScope.launch {
    udmRepository.getLinkDevices().collect { devices ->
        // Handle the list of devices
    }
}

// Update device name
viewModelScope.launch {
    udmRepository.updateDeviceName(
        uniqueId = "device_id",
        name = "New Device Name"
    ).collect {
        // Handle the update result
    }
}

// Remove a device
viewModelScope.launch {
    udmRepository.removeDevice("device_id").collect {
        // Handle the removal result
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://cramiumlabs.gitbook.io/docs/sdk-mpc-android/usage-guide-for-an-mpc-wallet-app/user-device-management-udm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
