Skip to content

Combined Bluetooth + P2P pairing

Purpose

Demonstrate one screen that chains classic Bluetooth attachment and Wi‑Fi P2P bonding to stand up the primary phone↔glasses link.

Entry points

Navigate from:

  • ClassicBtActivity after picking a device
  • MainPhoneActivity “connect” shortcut

Sample screen:

  • com.rokid.phone.ui.BtWifiConnectActivity

Platform

  • Phone

Main files

Flow

  1. Read route args to determine whether you need BT, P2P, or both this pass.
  2. If BT is required:
    • Resolve the target with BluetoothAdapter.getRemoteDevice().
    • Call connectToServer() for classic transport.
  3. After BT succeeds:
    • Persist the device record.
    • If P2P still needed, call sendConnectP2pRequest().
  4. Subscribe to IWifiP2PClientListener, find a WifiP2pDevice whose friendly name matches the active BT device, call connectDevice().
  5. Update global linkage state on success.

Key SDK pieces

  • Classic BT client connect API
  • Wi‑Fi P2P peer discovery + attach
  • Automated P2P connect request helper

Notes for developers

Why Bluetooth first, P2P second

Control-plane traffic and many status sync messages prefer the classic BT lane; large payloads and high bandwidth features lean on P2P. Establishing BT first keeps control messages stable while the data plane lights up.

How P2P peers are matched today

Implementation keys off display names:

  • DeviceLinkerManager.mConnectingBluetoothDevice?.name
  • WifiP2pDevice.deviceName

For production hardening, augment with stable hardware IDs.

Caveats

  • Timeout handling moves the screen to failure if nothing completes in time.
  • If phone Wi‑Fi is off, flow fails fast with a toast.
  • Identical device names from different units are not handled robustly yet.