BluetoothSocket Class
BluetoothSocket objects can be created by calling the createBluetoothSocket method. This is a workaround until TIMOB-13097 is fixed in Titanium.
The permanent solution will be to create these objects by calling the createSocket method on a BluetoothDevice object.
These objects can also be returned in connectionReceived events on BluetoothServerSocket objects.
Item Index
Methods
Properties
Events
Methods
cancelConnect
()
Void
Cancels the previously started connection attempt. If there is no connection attempt in progress, it does not do anything.
Returns:
close
()
Void
Closes the socket.
Returns:
connect
()
Void
Initiates the connection to the remote device. This is an asynchronous call. Listen for the connected event to be notified when the connection is established.
Returns:
getReadBufferSize
()
Number
Returns the size of the read buffer in bytes.
Returns:
Size of the read buffer in bytes.
getRemoteDevice
()
BluetoothDevice
Returns the BluetoothDevice object representing the device to which this socket is connected to.
Returns:
The object representing the device to which this socket is connected to.
isConnected
()
Boolean
Get the connection status of this socket, ie, whether there is an active connection with remote device.
This function requires API level 14 or higher.
Returns:
True if the socket is connected.
isConnecting
()
Boolean
Returns true if there is a connection attempt in progress, false otherwise.
Returns:
True if there is a connection attempt in progress, false otherwise.
setReadBufferSize
-
newReadBufferSize
Sets the size of the read buffer in bytes. You can set the read buffer size at any time, but it will only take effect during the next connection.
Parameters:
-
newReadBufferSize
NumberThe desired size of the read buffer in bytes.
Returns:
write
-
buffer
Sends an array of bytes over the socket. Use the Titanium.createBuffer function to create the buffer.
Parameters:
-
buffer
Ti.BufferThe data to be sent over the socket.
Returns:
Properties
readBufferSize
The size of the read buffer in bytes. You can set the read buffer size at any time, but it will only take effect during the next connection.
remoteDevice
BluetoothDevice
read-only
The object representing the device to which this socket is connected to.
Events
connected
Fired when the connection through the socket is established.
Event Payload:
-
socket
BluetoothSocketThe socket through which the connection was established.
error
Fired when an operation fails.
Event Payload:
-
socket
BluetoothSocketThe socket that experienced the error.
-
errorMessage
StringDescription of the error.
receiveData
Event Payload:
-
socket
BluetoothSocketThe socket on which the data was received.
-
data
Ti.Buffer