Getting Started on Java

Add the SDK to your project

build.gradle
repositories {
    mavenCentral()
    maven {
        url "https://bin.socketmobile.com/repo/releases"
    }
}

dependencies {
    implementation 'com.socketmobile:capture:1.6.3'
}

Note

Beta versions of the sdk will be distributed in https://bin.socketmobile.com/repo/snapshots

Start Capture

Create a singleton instance of CaptureClient at the highest appropriate scope for your application.

// Note: The second argument, <my app id>, is the colon separated platform and app id you used
// to generate your appkey - e.g. android:com.example.myapp
AppKey appkey = new AppKey("<my appkey>", "<my app id>", "<my developer id>");
CaptureClient client = new CaptureClient(appkey);
client.setListener(mListener);
client.connect(connectionCallback);

Where mListener implements the CaptureClient.Listener interface and connectionCallback implements the ConnectionCallback interface.

ConnectionCallback connectionCallback = new ConnectionCallback() {
    @override public void onConnectionStateChanged(ConnectionState state) {
        switch(state.get()) {
            case ConnectionState.CONNECTING:
                // do something or nothing
                break;
            case ConnectionState.CONNECTED:
                // client is now usable
                break;
            case ConnectionState.DISCONNECTING:
                // only called when shutting down gracefully
                break;
            case ConnectionState.DISCONNECTED:
                if(state.disconnectCausedByError()) {
                    // Handle error
                } else {
                    // Shut down normally
                }
            default:
                // Unreachable
                break;
        }
    }
}

The listener will be notified as Capture devices become usable or unusable.

@Override
public void onDeviceStateEvent(DeviceStateEvent event) {
    mDevice = event.getDevice();
    DeviceState state = event.getState()
    switch (state.intValue()) {
        case DeviceState.GONE:
            // Scanner is gone
            break;
        case DeviceState.AVAILABLE:
            // Scanner is connected to the service. You can choose to open the device or not.
            break;
        case DeviceState.OPEN:
            // Scanner is open, but you do not have control of it. It may be in the process of
            // opening or another application may have opened the scanner.
            break;
        case DeviceState.READY:
            // Scanner is ready. Configure scanner
            break;
    }
}

Most importantly, the listener will also be notified of decoded data

public void onData(DataEvent event) {
    DeviceClient device = event.getDevice();
    String data = event.getData().getString();
    // do something
}