Class LocalDevice
- java.lang.Object
-
- totalcross.io.device.bluetooth.LocalDevice
-
public class LocalDevice extends java.lang.ObjectTheLocalDeviceclass defines the basic functions of the Bluetooth manager. The Bluetooth manager provides the lowest level of interface possible into the Bluetooth stack. It provides access to and control of the local Bluetooth device.This class produces a singleton object.
- Since:
- TotalCross 1.15
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetBluetoothAddress()Retrieves the Bluetooth address of the local device.DeviceClassgetDeviceClass()Retrieves theDeviceClassobject that represents the service classes, major device class, and minor device class of the local device.intgetDiscoverable()Retrieves the local device's discoverable mode.DiscoveryAgentgetDiscoveryAgent()Returns the discovery agent for this device.java.lang.StringgetFriendlyName()Retrieves the name of the local device.static LocalDevicegetLocalDevice()Retrieves theLocalDeviceobject for the local Bluetooth device.static java.lang.StringgetProperty(java.lang.String property)ServiceRecordgetRecord(StreamConnectionNotifier notifier)Gets the service record corresponding to abtspp,btl2cap, orbtgoepnotifier.static booleanisPowerOn()Retrieves the power state of the local Bluetooth device.booleansetDiscoverable(int mode)Sets the discoverable mode of the device.voidupdateRecord(ServiceRecord srvRecord)
-
-
-
Method Detail
-
getBluetoothAddress
public java.lang.String getBluetoothAddress()
Retrieves the Bluetooth address of the local device. The Bluetooth address will never benull. The Bluetooth address will be 12 characters long. Valid characters are 0-9 and A-F.- Returns:
- the Bluetooth address of the local device
- Since:
- TotalCross 1.2
-
getDeviceClass
public DeviceClass getDeviceClass()
Retrieves theDeviceClassobject that represents the service classes, major device class, and minor device class of the local device. This method will returnnullif the service classes, major device class, or minor device class could not be determined.- Returns:
- the service classes, major device class, and minor device class of the local device, or
nullif the service classes, major device class or minor device class could not be determined - Since:
- TotalCross 1.2
-
getDiscoverable
public int getDiscoverable()
Retrieves the local device's discoverable mode. The return value will beDiscoveryAgent.GIAC,DiscoveryAgent.LIAC,DiscoveryAgent.NOT_DISCOVERABLE, or a value in the range 0x9E8B00 to 0x9E8B3F.- Returns:
- the discoverable mode the device is presently in
- Since:
- TotalCross 1.2
-
getDiscoveryAgent
public DiscoveryAgent getDiscoveryAgent()
Returns the discovery agent for this device. Multiple calls to this method will return the same object. This method will never returnnull.- Returns:
- the discovery agent for the local device
- Since:
- TotalCross 1.15
-
getFriendlyName
public java.lang.String getFriendlyName()
Retrieves the name of the local device. The Bluetooth specification calls this name the "Bluetooth device name" or the "user-friendly name".- Returns:
- the name of the local device;
nullif the name could not be retrieved - Since:
- TotalCross 1.2
-
getLocalDevice
public static LocalDevice getLocalDevice() throws IOException
Retrieves theLocalDeviceobject for the local Bluetooth device. Multiple calls to this method will return the same object. This method will never returnnull.- Returns:
- an object that represents the local Bluetooth device
- Throws:
IOException- if the Bluetooth system could not be initialized- Since:
- TotalCross 1.15
-
getProperty
public static java.lang.String getProperty(java.lang.String property)
-
isPowerOn
public static boolean isPowerOn()
Retrieves the power state of the local Bluetooth device.- Returns:
trueif the local Bluetooth device is powered on,falseif the local Bluetooth device is off.- Since:
- TotalCross 1.2
-
setDiscoverable
public boolean setDiscoverable(int mode) throws IOExceptionSets the discoverable mode of the device. Themodemay be any number in the range 0x9E8B00 to 0x9E8B3F as defined by the Bluetooth Assigned Numbers Document. When this specification was defined, only GIAC (DiscoveryAgent.GIAC) and LIAC (DiscoveryAgent.LIAC) were defined, but Bluetooth profiles may add additional access codes in the future. To determine what values may be used, check the Bluetooth Assigned Numbers document at http://www.bluetooth.org/assigned-numbers/baseband.htm. IfDiscoveryAgent.GIACorDiscoveryAgent.LIACare provided, then this method will attempt to put the device into general or limited discoverable mode, respectively. To take a device out of discoverable mode, provide theDiscoveryAgent.NOT_DISCOVERABLEflag. The BCC decides if the request will be granted. In addition to the BCC, the Bluetooth system could effect the discoverability of a device.According to the Bluetooth Specification, a device should only be limited discoverable (
DiscoveryAgent.LIAC) for 1 minute. This is handled by the implementation of the API. After the minute is up, the device will revert back to the previous discoverable mode.- Parameters:
mode- the mode the device should be in; valid modes areDiscoveryAgent.GIAC,DiscoveryAgent.LIAC,DiscoveryAgent.NOT_DISCOVERABLEand any value in the range 0x9E8B00 to 0x9E8B3F- Returns:
trueif the request succeeded, otherwisefalseif the request failed because the BCC denied the request;falseif the Bluetooth system does not support the access mode specified inmode- Throws:
java.lang.IllegalArgumentException- if themodeis notDiscoveryAgent.GIAC,DiscoveryAgent.LIAC,DiscoveryAgent.NOT_DISCOVERABLE, or in the range 0x9E8B00 to 0x9E8B3FIOException- if the Bluetooth system is in a state that does not allow the discoverable mode to be changed- See Also:
DiscoveryAgent.GIAC,DiscoveryAgent.LIAC,DiscoveryAgent.NOT_DISCOVERABLE
-
updateRecord
public void updateRecord(ServiceRecord srvRecord)
-
getRecord
public ServiceRecord getRecord(StreamConnectionNotifier notifier)
Gets the service record corresponding to abtspp,btl2cap, orbtgoepnotifier. In the case of a run-before-connect service, the service record returned bygetRecord()was created by the same call toConnector.open()that created thenotifier.If a connect-anytime server application does not already have a service record in the SDDB, either because a service record for this service was never added to the SDDB or because the service record was added and then removed, then the
ServiceRecordreturned bygetRecord()was created by the same call toConnector.open()that created the notifier.In the case of a connect-anytime service, there may be a service record in the SDDB corresponding to this service prior to application startup. In this case, the
getRecord()method must return aServiceRecordwhose contents match those of the corresponding service record in the SDDB. If a connect-anytime server application made changes previously to its service record in the SDDB (for example, during a previous execution of the server), and that service record is still in the SDDB, then those changes must be reflected in theServiceRecordreturned bygetRecord().Two invocations of this method with the same
notifierargument return objects that describe the same service attributes, but the return values may be different object references.- Parameters:
notifier- a connection that waits for clients to connect to a Bluetooth service- Returns:
- the
ServiceRecordassociated withnotifier - Throws:
java.lang.IllegalArgumentException- ifnotifieris closed, or ifnotifieris not a Bluetooth notifier, e.g., aStreamConnectionNotifiercreated with a scheme other thanbtspp.java.lang.NullPointerException- ifnotifierisnull
-
-