BluetoothAdmin allows you to administrate the Bluetooth adapter. Using this object you can enable or disable the adapter, monitor its state and discover devices in range. DiscoveryStarted and DiscoveryFinished events are raised when a discovery process starts or finishes. StateChanged event is raised whenever the adapter state changes. The new state and the previous state are passed. The values correspond to the STATE_xxxx constants. DeviceFound event is raised when a device is discovered. The device name and mac address are passed.
Cancels a discovery process. Returns False if the operation has failed.
DisableAsBoolean
Turns off the Bluetooth adapter. The adapter will not be immediately disabled. You should use the StateChanged event to monitor the adapter. This method returns False if the adapter cannot be disabled.
EnableAsBoolean
Turns on the Bluetooth adapter. The adapter will not be immediately ready. You should use the StateChanged event to find when it is enabled. This method returns False if the adapter cannot be enabled.
Initialize (EventNameAsString)
Initializes the object and sets the subs that will handle the events.
IsEnabledAsBoolean
Tests whether the Bluetooth adapter is enabled.
IsInitializedAsBoolean
Tests whether the object is initialized.
LastFoundIntentAsIntentWrapper [read only]
Can be used inside the DeviceFound event to extract more data from the intent received. Returns an uninitialized object if no intent was received.
StartDiscoveryAsBoolean
Starts a discovery process. You should handle DiscoveryStarted, DiscoveryFinished and DeviceFound events to get more information about the process. Returns False if the operation has failed.
The Serial library allows you to connect with other Bluetooth devices using RFCOMM, also named virtual serial port. This library requires Android 2.0 (API level 5) or above. The Serial object should be declared as a process global object. After initializing the object you can connect to other devices by calling Connect with the target device MAC address. This can be done by first getting the paired devices map. This map contains the friendly name and address of each paired device. To allow other devices to connect to your device you should call Listen. When a connection is established the Connected event will be raised. There is no problem with both listening to connections and trying to connect to a different device (this allows you to use the same application on two devices without defining a server and client). A Serial object can handle a single connection. If a new connection is established, it will replace the previous one. See this tutorial for more information.
Tries to connect to a device with the given address. The connection is done in the background. The Connected event will be raised when the connection is ready (or fails). The UUID used for the connection is the default UUID: 00001101-0000-1000-8000-00805F9B34FB.
Connect2 (MacAddressAsString, UUIDAsString)
Tries to connect to a device with the given address and UUID. The connection is done in the background. The Connected event will be raised when the connection is ready (or fails).
Connect3 (MacAddressAsString, PortAsInt)
This method is a workaround for hardware devices that do not connect with Connect or Connect2. See this issue for more information.
Tries to connect to a device over an unencrypted connection. Admin - Object of type BluetoothAdmin. MacAddress - The address of the remote device. Port - RCOMM channel.
Disconnect
Disconnects the connection (if such exists) and stops listening for new connections.
GetPairedDevicesAsMap
Returns a map with the paired devices friendly names as keys and addresses as values. The following code shows a list of available devices and allows the user to connect to one: DimPairedDevicesAsMap PairedDevices = Serial1.GetPairedDevices DimlAsList l.Initialize Fori = 0ToPairedDevices.Size - 1 l.Add(PairedDevices.GetKeyAt(i))
Next DimresAsInt res = InputList(l, "Choose device", -1) 'show list with paired devices Ifres <> DialogResponse.CANCELThen Serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address and connect EndIf
Initialize (EventNameAsString)
Initialized the object. You may want to call IsEnabled before trying to work with the object.
InputStreamAsjava.io.InputStream [read only]
Returns the InputStream that is used to read data from the other device. Should be called after a connection is established.
IsEnabledAsBoolean
Tests whether the Bluetooth is enabled.
IsInitializedAsBoolean
Listen
Starts listening for incoming connections using the default UUID. The Connected event will be raised when the connection is established. Nothing happens if the device already listens for connections.
Listen2 (NameAsString, UUIDAsString)
Starts listening for incoming connections. The Connected event will be raised when the connection is established. Nothing happens if the device already listens for connections. Name - An arbitrary string that will be used for internal registration. UUID - The UUID defined for this record.
ListenInsecure (AdminAsBluetoothAdmin, PortAsInt)
Starts listening for incoming unencrypted connections. Admin - An object of type BluetoothAdmin. Port - The RFCOMM channel.
NameAsString [read only]
Returns the current device friendly name.
OutputStreamAsjava.io.OutputStream [read only]
Returns the OutputStream that is used to write data to the other device. Should be called after a connection is established.
StopListening
Stops listening for incoming connections. This will not disconnect any active connection.
Top