public class RxBluetooth
extends java.lang.Object
Constructor and Description |
---|
RxBluetooth(android.content.Context context) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancelDiscovery()
Cancel the current device discovery process.
|
void |
closeProfileProxy(int profile,
android.bluetooth.BluetoothProfile proxy)
Close the connection of the profile proxy to the Service.
|
void |
enableBluetooth(android.app.Activity activity,
int requestCode)
This will issue a request to enable Bluetooth through the system settings (without stopping
your application) via ACTION_REQUEST_ENABLE action Intent.
|
void |
enableDiscoverability(android.app.Activity activity,
int requestCode)
This will issue a request to make the local device discoverable to other devices.
|
void |
enableDiscoverability(android.app.Activity activity,
int requestCode,
int duration)
This will issue a request to make the local device discoverable to other devices.
|
java.util.Set<android.bluetooth.BluetoothDevice> |
getBondedDevices()
Return the set of
BluetoothDevice objects that are bonded
(paired) to the local adapter. |
boolean |
isBluetoothAvailable()
Return true if Bluetooth is available.
|
boolean |
isBluetoothEnabled()
Return true if Bluetooth is currently enabled and ready for use.
|
boolean |
isDiscovering()
Return true if the local Bluetooth adapter is currently in the device
discovery process.
|
rx.Observable<AclEvent> |
observeAclEvent()
Observes ACL broadcast actions from
BluetoothDevice . |
rx.Observable<ServiceEvent> |
observeBluetoothProfile(int bluetoothProfile)
Observes connection to specified profile.
|
rx.Observable<android.bluetooth.BluetoothSocket> |
observeBluetoothSocket(java.lang.String name,
java.util.UUID uuid)
Opens
BluetoothServerSocket , listens for a single connection request, releases socket
and returns a connected BluetoothSocket on successful connection. |
rx.Observable<java.lang.Integer> |
observeBluetoothState()
Observes BluetoothState.
|
rx.Observable<BondStateEvent> |
observeBondState()
Observes bond state of devices.
|
rx.Observable<android.bluetooth.BluetoothSocket> |
observeConnectDevice(android.bluetooth.BluetoothDevice bluetoothDevice,
java.util.UUID uuid)
Create connection to
BluetoothDevice and returns a connected BluetoothSocket
on successful connection. |
rx.Observable<ConnectionStateEvent> |
observeConnectionState()
Observes connection state of devices.
|
rx.Observable<android.bluetooth.BluetoothDevice> |
observeDevices()
Observes Bluetooth devices found while discovering.
|
rx.Observable<java.lang.String> |
observeDiscovery()
Observes DiscoveryState, which can be ACTION_DISCOVERY_STARTED or ACTION_DISCOVERY_FINISHED
from
BluetoothAdapter . |
rx.Observable<java.lang.Integer> |
observeScanMode()
Observes scan mode of device.
|
boolean |
startDiscovery()
Start the remote device discovery process.
|
public boolean isBluetoothAvailable()
public boolean isBluetoothEnabled()
Equivalent to:
getBluetoothState() == STATE_ON
Requires Manifest.permission.BLUETOOTH
public void enableBluetooth(android.app.Activity activity, int requestCode)
activity
- ActivityrequestCode
- request codepublic java.util.Set<android.bluetooth.BluetoothDevice> getBondedDevices()
BluetoothDevice
objects that are bonded
(paired) to the local adapter.
If Bluetooth state is not BluetoothAdapter.STATE_ON
, this API
will return an empty set. After turning on Bluetooth,
wait for BluetoothAdapter.ACTION_STATE_CHANGED
with BluetoothAdapter.STATE_ON
to get the updated value.
Requires Manifest.permission.BLUETOOTH
.
BluetoothDevice
, or null on errorpublic boolean startDiscovery()
public boolean isDiscovering()
public boolean cancelDiscovery()
public void enableDiscoverability(android.app.Activity activity, int requestCode)
activity
- ActivityrequestCode
- request codepublic void enableDiscoverability(android.app.Activity activity, int requestCode, int duration)
activity
- ActivityrequestCode
- request codeduration
- discoverability duration in secondspublic rx.Observable<android.bluetooth.BluetoothDevice> observeDevices()
public rx.Observable<java.lang.String> observeDiscovery()
BluetoothAdapter
.public rx.Observable<java.lang.Integer> observeBluetoothState()
BluetoothAdapter.STATE_OFF
,
BluetoothAdapter.STATE_TURNING_ON
,
BluetoothAdapter.STATE_ON
,
BluetoothAdapter.STATE_TURNING_OFF
,public rx.Observable<java.lang.Integer> observeScanMode()
BluetoothAdapter.SCAN_MODE_NONE
,
BluetoothAdapter.SCAN_MODE_CONNECTABLE
,
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE
public rx.Observable<ServiceEvent> observeBluetoothProfile(int bluetoothProfile)
BluetoothProfile.ServiceListener
.bluetoothProfile
- bluetooth profile to connect to. Can be either BluetoothProfile.HEALTH
,BluetoothProfile.HEADSET
, BluetoothProfile.A2DP
,
BluetoothProfile.GATT
or BluetoothProfile.GATT_SERVER
.ServiceEvent
public void closeProfileProxy(int profile, android.bluetooth.BluetoothProfile proxy)
Clients should call this when they are no longer using the proxy obtained from observeBluetoothProfile(int)
.
Profile can be one of BluetoothProfile.HEALTH
,BluetoothProfile.HEADSET
,
BluetoothProfile.A2DP
, BluetoothProfile.GATT
or BluetoothProfile.GATT_SERVER
.
profile
- the Bluetooth profileproxy
- profile proxy objectpublic rx.Observable<ConnectionStateEvent> observeConnectionState()
ConnectionStateEvent
public rx.Observable<BondStateEvent> observeBondState()
BondStateEvent
public rx.Observable<android.bluetooth.BluetoothSocket> observeBluetoothSocket(java.lang.String name, java.util.UUID uuid)
BluetoothServerSocket
, listens for a single connection request, releases socket
and returns a connected BluetoothSocket
on successful connection. Notifies observers
with IOException
onError()
.name
- service name for SDP recorduuid
- uuid for SDP recordBluetoothSocket
on successful connectionpublic rx.Observable<android.bluetooth.BluetoothSocket> observeConnectDevice(android.bluetooth.BluetoothDevice bluetoothDevice, java.util.UUID uuid)
BluetoothDevice
and returns a connected BluetoothSocket
on successful connection. Notifies observers with IOException
onError()
.bluetoothDevice
- bluetooth device to connectuuid
- uuid for SDP recordBluetoothSocket
on successful connectionpublic rx.Observable<AclEvent> observeAclEvent()
BluetoothDevice
. Possible broadcast ACL action
values are:
BluetoothDevice.ACTION_ACL_CONNECTED
,
BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED
,
BluetoothDevice.ACTION_ACL_DISCONNECTED
AclEvent