Bluetooth Management

OpenAndroidBluetoothSetting

Open Android Bluetooth settings.

public static void OpenAndroidBluetoothSetting()

RegisterBluetoothCallback

Register bluetooth callback.

public static void RegisterBluetoothCallback(OnBtLocalStateCallback btAdapter,
                                             OnBtLocalScanCallback btDevice,
                                             OnBtDeviceBondCallback btDeviceBond,
                                             OnBtDeviceConnectionStateCallback btConDeviceState)

Parameter

Description

btAdapter

callback when local bluetooth on/off state change

btDevice

callback when bluetooth device scan finished

btDeviceBond

device bonding state, ref:DeviceBondState

btConDeviceState

callback when connected device state change

Prototype for OnBtLocalStateCallback

public delegate void OnBtLocalStateCallback(int state)

Parameter

Description

state

local bluetooth state

Prototype for OnBtLocalScanCallback

public delegate void OnBtLocalScanCallback(bool scanState, string deviceInfo)

Parameter

Description

scanState

true -> is scanning state

deviceInfo

bluetooth device info, exp:{"DeviceClass":1024,"address":"30:21:30:45:17:7B","name":"ifkoo Q8","rssi":-39}

Prototype for OnBtDeviceBondCallback

public delegate void OnBtDeviceBondCallback(string deviceName, int bondState)

Parameter

Description

deviceName

device name

bondState

device bond state

Prototype for OnBtDeviceConnectionStateCallback

public delegate void OnBtDeviceConnectionStateCallback(string name, int preState, int currentState);

Parameter

Description

name

device name

preState

device previous state

currentState

device current state

IsBluetoothEnabled

check local bluetooth is enabled

public static bool IsBluetoothEnabled()

UnregisterBluetoothCallback

unregister bluetooth callback.

Warning: this method will remove all bluetooth listeners registered

public static void UnregisterBluetoothCallback()

GetConnectedDeviceNameList

get connected device name list

public static string[] GetConnectedDeviceNameList()

SetBluetoothEnabled

enable/disable local bluetooth state

public static bool SetBluetoothEnabled(bool enable)

Parameter

Description

enable

  • true -> enable bluetooth

  • false -> disable bluetooth

GetBluetoothState

get local bluetooth state

public static int GetBluetoothState()

GetLocalName

get local bluetooth name

public static string GetLocalName()

SetLocalName

set local bluetooth device name

public static bool SetLocalName(string localName)

Parameter

Description

localName

local bluetooth name user want

StartDiscovery

start scan bluetooth device

public static bool StartDiscovery()

IsDiscovering

Return true if the local Bluetooth adapter is currently in the device discovery process

public static bool IsDiscovering()

CancelDiscovery

public static bool CancelDiscovery()

Cancel the current device discovery process

GetBluetoothBondedDevices

Return the json string of objects that are bonded (paired) to the local adapter.

public static string GetBluetoothBondedDevices()

ConnectBluetoothDevice

Connect bluetooth device by address

warning: only supported DeviceClass is AUDIO_VIDEO or PERIPHERAL

public static bool ConnectBluetoothDevice(string address)

Parameter

Description

address

device address

RemoveBluetoothDevice

remove bluetooth device

public static bool RemoveBluetoothDevice(string address)

Parameter

Description

address

device address

Last updated