Android: Connect via Bluetooth
This guide shows how to integrate @onekeyfe/hd-common-connect-sdk in a native Android host via a low-level adapter. The JavaScript bundle runs in a WebView; transport calls are forwarded to native (Nordic BLE) and bridged back to JS.
Key libraries:
WebView JS bridge:
com.smallbuer:jsbridge:1.0.7Nordic BLE (Kotlin, ≥ 1.1.0):
no.nordicsemi.android.kotlin.ble:scanner:1.1.0no.nordicsemi.android.kotlin.ble:client:1.1.0Reason:
includeStoredBondedDevicesinBleScannerSettingsrequires > 1.0.9
OneKey BLE UUIDs:
Service:
00000001-0000-1000-8000-00805f9b34fbWrite:
00000002-0000-1000-8000-00805f9b34fbNotify:
00000003-0000-1000-8000-00805f9b34fb
Step 1. Gradle and Manifest
Gradle (app/build.gradle.kts):
dependencies {
implementation("com.smallbuer:jsbridge:1.0.7")
implementation("no.nordicsemi.android.kotlin.ble:scanner:1.1.0")
implementation("no.nordicsemi.android.kotlin.ble:client:1.1.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
}Android 12+ permissions (AndroidManifest.xml):
Runtime permissions (Kotlin):
Step 2. Build the web bundle (already implemented in the demo)
Inside the hardware-js-sdk repo:
Copy the entire output folder into your Android project:
Copy
web/web_dist/→app/src/main/assets/web_dist/The entry file will be available as:
app/src/main/assets/web_dist/index.html
No further JS work is required in the native app; the demo’s web bundle already initializes env: 'lowlevel' and wires the low-level adapter.
Step 3. WebView + Bridge (register before loading)
Step 4. BLE scan (include stored bonded devices)
Bridge handler for enumerate:
Step 5. Connect, characteristics, notifications
Step 6. Send / disconnect
Step 7. JavaScript bundle (low-level adapter)
The demo’s web project already builds a bundle that initializes the SDK with env: 'lowlevel' and wires the low-level adapter. You typically do NOT need to write extra JS — just build and copy web/web_dist/ into app/src/main/assets/web_dist/ and load file:///android_asset/web_dist/index.html.
If you customize the adapter, the core idea remains: initialize with env: 'lowlevel' and forward enumerate/connect/disconnect/send/receive via the bridge.
Step 8. UI events (PIN / Passphrase)
Handle UI_EVENT in your JS bundle and respond with HardwareSDK.uiResponse. See Config Event for event wiring and the WebUSB guide for minimal, production-ready dialogs.
PIN on device:
payload: '@@ONEKEY_INPUT_PIN_IN_DEVICE'Passphrase on device:
{ passphraseOnDevice: true, value: '' }
Step 9. Checklist
Nordic BLE library version ≥ 1.1.0 to use
includeStoredBondedDevices.Register handlers before loading the HTML to avoid race conditions.
Request runtime permissions on Android 12+ before scanning/connecting.
Persist
connectId(MAC) and cachedevice_idviagetFeatures(connectId)after the first connection.
References
Message Protocol (64‑byte framing): OneKey Message Protocol
Low‑level transport plugin contract: Low-level Transport Plugin
Last updated
Was this helpful?