# Device

The Capture SDK can be connected to `bd tail` session through the use of a Device Identifier or Device Code.

## Identifier

The device identifier can be obtained using the device identifier property on the Capture Logger. The identifier remains consistent as long as the host application is not reinstalled.

It can be used with the deviceid operator in the [bd tail CLI command](../../cli/quickstart.md#log-tailing) to stream logs directly from the device in real-time.

=== "Android (kotlin)"

    ```kotlin
    Logger.deviceId
    ```

=== "Android (Java)"

    ```java
    Logger.getDeviceId()
    ```

=== "iOS (Swift)"

    ```swift
    Logger.deviceID
    ```

=== "iOS (Objective-C)"

    ```objective-c
    [CAPLogger deviceID]
    ```

=== "React Native"

    ```javascript
    import { getDeviceId } from '@bitdrift/react-native';

    getDeviceId().then((deviceId) => {
      // Use deviceId
    }).catch((error) => {
      // Handle error
    });
    ```


## Code

Calling `Logger.createTemporaryDeviceCode` will asynchronously return a device code that's valid for a limited duration of time (around a day).

It can be used with the `devicecode` operator in the [bd tail CLI command](../../cli/quickstart.md#log-tailing) to stream logs directly from the device in real-time.

=== "Android (kotlin)"

    ```kotlin
    import com.github.michaelbull.result.onFailure
    import com.github.michaelbull.result.onSuccess
    import io.bitdrift.capture.Capture.Logger

    // Result uses https://github.com/michaelbull/kotlin-result
    Logger.createTemporaryDeviceCode(completion = { result ->
        result.onSuccess { deviceCode ->
            // Display code
        }
        result.onFailure { error ->
            // Handle error
        }
    })
    ```

=== "Android (Java)"

    ```java
    import com.github.michaelbull.result.OnKt;
    import io.bitdrift.capture.Capture.Logger;

    // Result uses https://github.com/michaelbull/kotlin-result
    Logger.createTemporaryDeviceCode(result -> {
        OnKt.onSuccess(result, deviceCode -> {
            // Display code
            return null;
        });
        OnKt.onFailure(result, error -> {
            // Handle error
            return null;
        });
        return null;
    });
    ```

=== "iOS (Swift)"

    ```swift
    Logger.createTemporaryDeviceCode { result in
       switch result {
         case .success(let deviceCode):
            // Display code
         case .failure(let error):
            // Handle error
       }
    }
    ```

=== "React Native"

    ```javascript
    import { generateDeviceCode } from '@bitdrift/react-native';

    generateDeviceCode().then((deviceCode) => {
      // Display code
    }).catch((error) => {
      // Handle error
    });
    ```
