public class BluetoothUtility
extends java.lang.Object
implements android.bluetooth.BluetoothProfile.ServiceListener
| Modifier and Type | Class and Description |
|---|---|
static class |
BluetoothUtility.InputStreamType
Type of input streams that can be used for reading bluetooth data.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
REQUEST_BLUETOOTH
Bluetooth Request constant.
|
static int |
REQUEST_BLUETOOTH_SCAN
Request code for a bluetooth scan.
|
| Constructor and Description |
|---|
BluetoothUtility(android.content.Context context,
android.app.Activity refActivity,
BluetoothHandler handler)
Constructor for
BluetoothUtility This class is a wrapper class for a BluetoothAdapter and makes a lot of its functionality easier. |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelScan()
Cancels the scanning process.
|
boolean |
checkIfEnabled()
Checks to see if bluetooth is enabled.
|
void |
closeConnections()
Closes all the connections.
|
void |
connectA2DPProxy(android.bluetooth.BluetoothA2dp bluetoothA2dp,
android.bluetooth.BluetoothDevice a2dpDevice)
After a proxy is returned, this method connects the a2dp device using the proxy and the
class declared method.
|
void |
connectDevice(java.lang.String macAddress)
Connects a device given a mac address.
|
void |
connectToClientToBluetoothServer(java.lang.String macAddress)
Connects to a set up server socket.
|
void |
createBluetoothServerSocket()
Creates a server socket on this device that awaits for a client connection.
|
void |
enableBluetooth()
Enables Bluetooth, BluetoothBroadCastReceiver should be used if you want to see the result.
|
void |
enableDiscovery(int duration)
Enables the device to be discoverable for a certain duration.
|
android.bluetooth.BluetoothDevice |
findDeviceByMacAddress(java.lang.String macAddress)
Helper method that finds a device given its mac address.
|
android.bluetooth.BluetoothDevice |
findDeviceByName(java.lang.String name)
Helper method that finds a device given its name.
|
java.util.ArrayList<android.bluetooth.BluetoothDevice> |
getPairedDevices()
Returns all the paired devices on this device.
|
void |
onServiceConnected(int i,
android.bluetooth.BluetoothProfile bluetoothProfile) |
void |
onServiceDisconnected(int i) |
void |
scan() |
void |
sendData(int number)
Sends a integer to the bluetooth device.
|
void |
sendData(java.lang.String data)
Sends a string of data to the bluetooth device.
|
void |
setInputStreamType(BluetoothUtility.InputStreamType type)
Sets the input stream type for the bluetooth device input stream.
|
void |
setUpA2DPConnection()
Gets the profile proxy for an A2DP connection.
|
public static final int REQUEST_BLUETOOTH
public static final int REQUEST_BLUETOOTH_SCAN
public BluetoothUtility(android.content.Context context,
android.app.Activity refActivity,
BluetoothHandler handler)
BluetoothUtility This class is a wrapper class for a BluetoothAdapter and makes a lot of its functionality easier.context - context from the calling activity or fragment.refActivity - reference to the calling activity.handler - a handler for handling read data and other messages. See
BluetoothHandler for more information.public void scan()
public android.bluetooth.BluetoothDevice findDeviceByName(java.lang.String name)
name - the name of the device.BluetoothDevice object if it was found. Returns null otherwise.public android.bluetooth.BluetoothDevice findDeviceByMacAddress(java.lang.String macAddress)
macAddress - the mac address of the device.BluetoothDevice object if it was found. Returns null otherwise.public java.util.ArrayList<android.bluetooth.BluetoothDevice> getPairedDevices()
public void enableDiscovery(int duration)
duration - the duration in milliseconds.public boolean checkIfEnabled()
public void enableBluetooth()
public void setInputStreamType(BluetoothUtility.InputStreamType type)
type, - the input stream type.public void connectDevice(java.lang.String macAddress)
macAddress - the mac address of the device.public void setUpA2DPConnection()
public void onServiceConnected(int i,
android.bluetooth.BluetoothProfile bluetoothProfile)
onServiceConnected in interface android.bluetooth.BluetoothProfile.ServiceListenerpublic void onServiceDisconnected(int i)
onServiceDisconnected in interface android.bluetooth.BluetoothProfile.ServiceListenerpublic void connectA2DPProxy(android.bluetooth.BluetoothA2dp bluetoothA2dp,
android.bluetooth.BluetoothDevice a2dpDevice)
bluetoothA2dp - an A2DP proxya2dpDevice - a BluetoothDevice that is an A2DP device.public void closeConnections()
public void sendData(java.lang.String data)
data - the string to send.public void cancelScan()
public void sendData(int number)
number - the integer to send.public void connectToClientToBluetoothServer(java.lang.String macAddress)
macAddress - the mac address of the device hosting the server socket.public void createBluetoothServerSocket()