# Connect to our products with Companion and CaptureSDK

Guide for connecting Socket Mobile Bluetooth Low Energy (BLE) devices using the Socket Mobile Companion app, which handles device discovery and selection. Covers device arrival and removal event handling, multi-function device management (combo barcode scanner + NFC reader), and device type identification. The Companion app is available on iOS (App Store), Android (Google Play) and Windows (GitHub releases). Includes code samples for device arrival and removal events.

First install our **Socket Mobile Companion app** (use the right link below for your platform) which takes care of the discovery and the selection of the reader to connect to.

- Android: [Google Play](https://play.google.com/store/apps/details?id=com.socketmobile.companion)

- iOS: [AppStore](https://apps.apple.com/app/socket-mobile-companion/id1175638950)

- Windows: [GitHub](https://github.com/SocketMobile/companion-windows/releases)

Then initialize **CaptureSDK**. Please refer to [Capture Helper initialization](/docs/using-capturesdk/capture-helper).

## Device events

In terms of code, you just need to implement the **device arrival and removal events** — delivered by **CaptureHelper** on iOS, C#, JavaScript and Dart, or as the **DeviceStateEvent** EventBus event on Android — to be notified when a device is connected or disconnected.

## Java

```java
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void onCaptureDeviceStateChange(DeviceStateEvent event) {
    DeviceClient device = event.getDevice();
    DeviceState state = event.getState();

    switch (state.intValue()) {
        case DeviceState.READY:
            // Device arrival: device is connected and ready to use
            Log.d(TAG, "Device arrival: " + device.getDeviceType());
            break;
        case DeviceState.GONE:
            // Device removal: device has been disconnected
            Log.d(TAG, "Device removal: " + device.getDeviceType());
            break;
        default:
            break;
    }
}
```

## Kotlin

```kotlin
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
fun onCaptureDeviceStateChange(event: DeviceStateEvent) {
    val device = event.device
    val state = event.state

    when (state.intValue()) {
        DeviceState.READY -> {
            // Device arrival: device is connected and ready to use
            Log.d(TAG, "Device arrival: ${device.deviceType}")
        }
        DeviceState.GONE -> {
            // Device removal: device has been disconnected
            Log.d(TAG, "Device removal: ${device.deviceType}")
        }
    }
}
```

## Swift

```swift
func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
    print("didNotifyArrivalForDevice: \(device.deviceInfo.name ?? "") - Result: \(result.rawValue)")
}

func didNotifyRemovalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
    print("didNotifyRemovalForDevice: \(device.deviceInfo.name ?? "") - Result: \(result.rawValue)")
}
```

## C#

```csharp
// capture is of type "CaptureHelper" and is initialized
capture.DeviceArrival += Capture_DeviceArrival;
capture.DeviceRemoval += Capture_DeviceRemoval;

private void Capture_DeviceArrival(object sender, CaptureHelper.DeviceArgs e)
{
    CaptureHelperDevice device = e.CaptureDevice;
    Console.WriteLine($"Device arrival: {device.GetDeviceInfo().Name}");
}

private void Capture_DeviceRemoval(object sender, CaptureHelper.DeviceArgs e)
{
    CaptureHelperDevice device = e.CaptureDevice;
    Console.WriteLine($"Device removal: {device.GetDeviceInfo().Name}");
}
```

## Dart

```dart
final CaptureHelper _helper = CaptureHelper();

Future<void> _openHelper() async {
  await _helper.open(
    appInfo,

    onDeviceArrival: (CaptureHelperDevice device) {
      setState(() {
        _devices = _helper.getDevices();
      });
    },

    onDeviceRemoval: (CaptureHelperDevice device) {
      setState(() {
        _devices = _helper.getDevices();
      });
    },

    ...

  );
}
```

## JavaScript

```javascript
  const helperRef = useRef<CaptureHelper | null>(null);

  useEffect(() => {
    const helper = new CaptureHelper({
      appInfo,

      onDeviceArrival: (device) => {
        setDevices(d => [...d, device]);
      },

      onDeviceRemoval: (device) => {
        setDevices(d => d.filter(dd => dd.guid !== device.guid));
      },

      ...
    });
  }, []);
```

## Additional context

For a combo device like the S370 which has 2 devices, there will be two **device arrival events** and two **device removal events**. The following code shows how you can distinguish and handle them:

## Java

```java
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void onCaptureDeviceStateChange(DeviceStateEvent event) {
    DeviceClient device = event.getDevice();
    DeviceState state = event.getState();

    switch (state.intValue()) {
        case DeviceState.READY:
            if (device.getDeviceType() == DeviceType.kModelNfcS370) {
                // handle the NFC reader of the S370
            } else if (device.getDeviceType() == DeviceType.kModelScannerS370) {
                // handle the Barcode scanner of the S370
            }
            break;
        default:
            break;
    }
}
```

## Kotlin

```kotlin
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
fun onCaptureDeviceStateChange(event: DeviceStateEvent) {
    val device = event.device
    val state = event.state

    when (state.intValue()) {
        DeviceState.READY -> {
            when (device.deviceType) {
                DeviceType.kModelNfcS370 -> {
                    // handle the NFC reader of the S370
                }
                DeviceType.kModelScannerS370 -> {
                    // handle the Barcode scanner of the S370
                }
            }
        }
    }
}
```

## Swift

```swift
func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
  print("didNotifyArrivalForDevice: \(String(describing: device.deviceInfo.name))")
  if device.deviceInfo.deviceType == .NFCS370 {
    // handle the NFC reader of the S370
  } else if device.deviceInfo.deviceType == .scannerS370 {
    // handle the Barcode scanner of the S370
  }
}
```

## C#

```csharp
private void Capture_DeviceArrival(object sender, CaptureHelper.DeviceArgs e)
{
    int deviceType = e.CaptureDevice.GetDeviceInfo().Type;

    if (deviceType == DeviceTypes.kNFCS370)
    {
        // handle the NFC reader of the S370
    }
    else if (deviceType == DeviceTypes.kScannerS370)
    {
        // handle the Barcode scanner of the S370
    }
}
```

## Dart

```dart
onDeviceArrival: (CaptureHelperDevice device) {
  if (device.type == CaptureDeviceType.nFCS370) {
    // Handle the NFC reader of the S370
  } else if (device.type == CaptureDeviceType.scannerS370) {
    // Handle the Barcode scanner of the S370
  }
},
```

## JavaScript

```javascript
const helper = new CaptureHelper({
  onDeviceArrival: (device) => {
    if (device.type === CaptureDeviceType.NFCS370) {
      // handle the NFC reader of the S370
    } else if (device.type === CaptureDeviceType.ScannerS370) {
      // handle the Barcode scanner of the S370
    }
  },
});
```

You can also check if a device is barcode reader or a NFC reader when you get the **device arrival event**:

## Java

```java
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void onCaptureDeviceStateChange(DeviceStateEvent event) {
    DeviceClient device = event.getDevice();
    DeviceState state = event.getState();

    switch (state.intValue()) {
        case DeviceState.READY:
            if (DeviceType.isNfcScanner(device.getDeviceType())) {
                // handle the NFC reader of the S370 or another NFC reader like a S550
            } else if (DeviceType.isBarcodeScanner(device.getDeviceType())) {
                // handle the Barcode scanner of the S370 or another barcode scanner like a S320 or S740
            }
            break;
        default:
            break;
    }
}
```

## Kotlin

```kotlin
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
fun onCaptureDeviceStateChange(event: DeviceStateEvent) {
    val device = event.device
    val state = event.state

    when (state.intValue()) {
        DeviceState.READY -> {
            when {
                DeviceType.isNfcScanner(device.deviceType) -> {
                    // handle the NFC reader of the S370 or another NFC reader like a S550
                }
                DeviceType.isBarcodeScanner(device.deviceType) -> {
                    // handle the Barcode scanner of the S370 or another barcode scanner like a S320 or S740
                }
            }
        }
    }
}
```

## Swift

```swift
func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
  print("didNotifyArrivalForDevice: \(String(describing: device.deviceInfo.name))")
  if device.isNFCReader {
    // handle the NFC reader of the S370 or another NFC reader like a S550
  } else if device.isBarcodeReader {
    // handle the Barcode scanner of the S370 or another barcode scanner like a S320 or S740
  }
}
```

## C#

```csharp
private void Capture_DeviceArrival(object sender, CaptureHelper.DeviceArgs e)
{
    CaptureHelperDevice device = e.CaptureDevice;

    if (device.IsNFCReader())
    {
        // handle the NFC reader of the S370 or another NFC reader like a S550
    }
    else if (device.IsBarcodeReader())
    {
        // handle the Barcode scanner of the S370 or another barcode scanner like a S320 or S740
    }
}
```

## Dart

```dart
// Coming soon
```

## JavaScript

```javascript
// Coming soon
```