@matfire/ionic_bluetooth_classic
v0.0.6
Published
bluetooth discovery and communication
Downloads
7
Maintainers
Readme
bluetooth
bluetooth classic discovery and communication
currently only works on Android, IOS coming eventually
Install
npm install @matfire/ionic_bluetooth_classic
npx cap sync
Permissions
Android
add the following lines to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
API
checkPermissions()
requestPermissions()
startListening()
stopListening()
write(...)
addListener('deviceConnectionStatusChanged', ...)
addListener('deviceDataReceived', ...)
addListener('deviceDiscovered', ...)
getPairedDevices()
connect(...)
disconnect()
- Interfaces
- Type Aliases
- Enums
checkPermissions()
checkPermissions() => Promise<PermissionStatus>
Returns: Promise<PermissionStatus>
requestPermissions()
requestPermissions() => Promise<PermissionStatus>
Returns: Promise<PermissionStatus>
startListening()
startListening() => Promise<boolean>
Returns: Promise<boolean>
stopListening()
stopListening() => Promise<boolean>
Returns: Promise<boolean>
write(...)
write(data: { message: string; }) => Promise<boolean>
| Param | Type |
| ---------- | --------------------------------- |
| data
| { message: string; } |
Returns: Promise<boolean>
addListener('deviceConnectionStatusChanged', ...)
addListener(eventName: 'deviceConnectionStatusChanged', listenerFunc: ({ data }: { data: IDeviceStatus; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName
| 'deviceConnectionStatusChanged' |
| listenerFunc
| ({ data }: { data: IDeviceStatus; }) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
addListener('deviceDataReceived', ...)
addListener(eventName: 'deviceDataReceived', listenerFunc: ({ data }: { data: IDataReceived; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName
| 'deviceDataReceived' |
| listenerFunc
| ({ data }: { data: IDataReceived; }) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
addListener('deviceDiscovered', ...)
addListener(eventName: 'deviceDiscovered', listenerFunc: ({ device }: { device: IDevice; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
| Param | Type |
| ------------------ | --------------------------------------------------------------------------------- |
| eventName
| 'deviceDiscovered' |
| listenerFunc
| ({ device }: { device: IDevice; }) => void |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
getPairedDevices()
getPairedDevices() => Promise<{ devices: any[]; }>
Returns: Promise<{ devices: any[]; }>
connect(...)
connect(data: { deviceId: string; appUUID: string; }) => Promise<boolean>
| Param | Type |
| ---------- | --------------------------------------------------- |
| data
| { deviceId: string; appUUID: string; } |
Returns: Promise<boolean>
disconnect()
disconnect() => Promise<boolean>
Returns: Promise<boolean>
Interfaces
PermissionStatus
| Prop | Type |
| --------------- | ----------------------------------------------------------- |
| bluetooth
| PermissionState |
| location
| PermissionState |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove
| () => Promise<void> |
IDeviceStatus
| Prop | Type |
| -------------- | ----------------------------------------------------- |
| deviceId
| string |
| status
| DeviceStatus |
IDataReceived
| Prop | Type |
| ----------- | ------------------- |
| bytes
| string |
| size
| number |
IDevice
| Prop | Type |
| ------------- | ------------------- |
| address
| string |
| name
| string |
Type Aliases
PermissionState
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
Enums
DeviceStatus
| Members | Value |
| ------------------ | -------------- |
| DISCONNECTED
| 0 |
| CONNECTED
| 1 |
| CONNECTING
| 2 |