|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.gerdavax.android.bluetooth.LocalBluetoothDevice
public final class LocalBluetoothDevice
This class is the entry point of the Android Bluetooth Library. It implements
a singleton pattern.
WARNING: do not forget to invoke close(Context) when your application
leaves, otherwise the LocalBluetoothDevice may not work on next
invocations.
First step for using the Bluetooth services is to initialize the instance of
the LocalBluetoothDevice:
LocalBluetoothDevice localBluetoothDevice = LocalBluetoothDevice.init(context);where
context
is the context of Activity which manages the
LocalBluetoothDevice instance. Bluetooth service status (enabled/disabled)
can be retrieved using method
localBluetoothDevice.isEnabled();and the service can be enabled and disabled using method
localBluetoothDevice.setEnabled(boolean);To start scanning (discovery) of surrounding Bluetooth devices just invoke the
localBluetoothDevice.scan();method. Both service on/off and device scanning are asynchronous processes, therefore to receive notification about that, the application must provide a LocalBluetoothDeviceListener and set it to the LocalBluetoothDevice instance.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface it.gerdavax.android.bluetooth.BluetoothDevice |
---|
BluetoothDevice.BluetoothClasses, BluetoothDevice.BluetoothProfiles, BluetoothDevice.BluetoothProtocols |
Field Summary | |
---|---|
static int |
SCAN_MODE_CONNECTABLE
The local device is connectable, however it is not discoverable |
static int |
SCAN_MODE_CONNECTABLE_DISCOVERABLE
The local device is both discoverable and connectable |
static int |
SCAN_MODE_NONE
The local device is not discoverable nor connectable |
Method Summary | |
---|---|
void |
clearSystemNotification()
Removes the "Pin requested" notification from the notification area |
void |
close()
Closes the LocalBluetoothDevice and unregisters any Bluetooth service broadcast listener. |
java.lang.String |
getAddress()
Gets the BD Address of local device |
java.lang.String |
getCompany()
|
static LocalBluetoothDevice |
getLocalDevice()
Gets unique instance of LocalBluetoothDevice. |
java.lang.String |
getManufacturer()
|
java.lang.String |
getName()
Gets friendly name assigned to local device |
RemoteBluetoothDevice |
getRemoteBluetoothDevice(java.lang.String address)
|
int |
getRemoteClass(java.lang.String address)
|
int |
getScanMode()
Returns current scan mode |
static LocalBluetoothDevice |
initLocalDevice(android.content.Context context)
|
boolean |
isEnabled()
|
boolean |
isScanning()
Checks if scanning is in progress |
BluetoothSocket |
openServerSocket()
Opens a server socket on the first available channel (between 12 and 30) |
BluetoothSocket |
openServerSocket(int channel)
Opens a server socket on given channel (between 12 and 30) |
void |
scan()
Starts discovery process for remote Bluetooth devices |
boolean |
setEnabled(boolean enabled)
Enables the Bluetooth service on this handset |
void |
setListener(LocalBluetoothDeviceListener listener)
Sets the LocalBluetoothDeviceListener which will receive events about Bluetooth activation and device discovery progress WARNING: all invocations to the listener are synchronous, therefore listener's method implementation must avoid long operations. |
void |
setScanMode(int mode)
Configures current scan mode |
void |
showDefaultPinInputActivity(java.lang.String address,
boolean clearSystemNotification)
Shows system activity to input PIN for assigned device Thanks to Emanuele Di Saverio |
void |
stopScanning()
Stops current device scanning (only if it has been started by this LocalBluetoothDevice) |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SCAN_MODE_NONE
public static final int SCAN_MODE_CONNECTABLE
public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE
Method Detail |
---|
public static LocalBluetoothDevice initLocalDevice(android.content.Context context) throws java.lang.Exception
context
- the context of the Activity which uses the
LocalBluetoothDevice
java.lang.Exception
- if system's Bluetooth service can't be addressedpublic static LocalBluetoothDevice getLocalDevice() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public java.lang.String getAddress() throws BluetoothException
getAddress
in interface BluetoothDevice
java.lang.Exception
BluetoothException
public java.lang.String getName() throws BluetoothException
getName
in interface BluetoothDevice
BluetoothException
public java.lang.String getManufacturer() throws java.lang.Exception
java.lang.Exception
public java.lang.String getCompany() throws java.lang.Exception
java.lang.Exception
public void scan() throws java.lang.Exception
java.lang.Exception
public boolean isScanning() throws java.lang.Exception
java.lang.Exception
public void stopScanning() throws java.lang.Exception
java.lang.Exception
public void setListener(LocalBluetoothDeviceListener listener)
listener
- public int getRemoteClass(java.lang.String address) throws java.lang.Exception
address
-
java.lang.Exception
public void close()
public boolean isEnabled() throws java.lang.Exception
java.lang.Exception
public boolean setEnabled(boolean enabled) throws BluetoothException
enabled
-
BluetoothException
public RemoteBluetoothDevice getRemoteBluetoothDevice(java.lang.String address)
address
- the BDADDR (address) of required device
public int getScanMode() throws java.lang.Exception
java.lang.Exception
public void setScanMode(int mode) throws java.lang.Exception
java.lang.Exception
public BluetoothSocket openServerSocket() throws BluetoothException
BluetoothException
public BluetoothSocket openServerSocket(int channel) throws BluetoothException
BluetoothException
public void showDefaultPinInputActivity(java.lang.String address, boolean clearSystemNotification)
public void clearSystemNotification()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |