public class BluetoothStatusConnection extends ConnectionStatusA
BluetoothConnection
.
package test.zebra.android.comm.examples;
import android.os.Looper;
import com.zebra.sdk.comm.BluetoothStatusConnection;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.printer.SGD;
public class BluetoothStatusConnectionExample {
public static void main(String[] args) {
BluetoothStatusConnectionExample example = new BluetoothStatusConnectionExample();
String theBtMacAddress = "00:11:BB:DD:55:FF";
example.sendJSONOverStatusChannel(theBtMacAddress);
}
private void sendJSONOverStatusChannel(final String theBtMacAddress) {
new Thread(new Runnable() {
public void run() {
try {
// Instantiate a status only connection for given Bluetooth® MAC Address.
Connection thePrinterConn = new BluetoothStatusConnection(theBtMacAddress);
// Initialize
Looper.prepare();
// Open the connection - physical connection is established here.
thePrinterConn.open();
// This sends down JSON to the status channel to retrieve the 'appl.name' setting
String firmwareVersion = SGD.GET("appl.name", thePrinterConn);
System.out.println("The firmware version is : " + firmwareVersion);
// Close the connection to release resources.
thePrinterConn.close();
Looper.myLooper().quit();
} catch (Exception e) {
// Handle communications error here.
e.printStackTrace();
}
}
}).start();
}
}
Note: In order to
connect to a device with Bluetooth®, the device must be discoverable, authentication must be enabled, and the
authentication pin must be set (1-16 alphanumeric characters).Constructor and Description |
---|
BluetoothStatusConnection(String macAddress)
Constructs a new status only Bluetooth® connection with the given
macAddress . |
BluetoothStatusConnection(String macAddress,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Constructs a new status only Bluetooth® connection with the given
macAddress and timeout values. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the Bluetooth® connection.
|
String |
getFriendlyName()
Returns the friendly name of the Bluetooth® connection.
|
String |
getMACAddress()
Returns the MAC address which was passed into the constructor.
|
String |
getSimpleConnectionName()
Return the MAC address and friendly name of the status port as the description.
|
void |
open()
Opens a status only Bluetooth® connection as specified in the constructor.
|
String |
toString()
Returns
Bluetooth_STATUS :[MAC Address]:[Friendly Name].The friendly name is obtained from the device when this connection is opened. |
bytesAvailable, getConnectionReestablisher, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write, write, write
bytesAvailable, getConnectionReestablisher, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write, write, write
public BluetoothStatusConnection(String macAddress)
macAddress
. The MAC address is
a hexadecimal string with or without separators between the octets. (e.g. 00:11:BB:DD:55:FF or 0011BBDD55FF).
This constructor will use the default timeouts for Connection.read()
. The default timeout is a maximum of
5 seconds for any data to be received. If no more data is available after 500 milliseconds the read operation is
assumed to be complete.BluetoothStatusConnection(String, int, int)
.macAddress
- the device's MAC address.public BluetoothStatusConnection(String macAddress, int maxTimeoutForRead, int timeToWaitForMoreData)
macAddress
and timeout values.
The MAC address is a hexadecimal string with or without separators between the octets. (e.g. 00:11:BB:DD:55:FF or
0011BBDD55FF). This constructor will use the specified timeouts for Connection.read()
. The timeout is a
maximum of maxTimeoutForRead
milliseconds for any data to be received. If no more data is available
after timeToWaitForMoreData
milliseconds the read operation is assumed to be complete.macAddress
- the device's MAC address.maxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received.timeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the initial read.public void open() throws ConnectionException
Note that if the device does not support status connections (that is, if it is not a Link-OS 2.5 or higher device) calling open will throw a ConnectionException.
open
in interface Connection
open
in class ConnectionA
ConnectionException
ConnectionA.open()
public void close() throws ConnectionException
close
in interface Connection
close
in class ConnectionA
ConnectionException
- if an I/O error occurs.Connection.close()
public String toString()
Bluetooth_STATUS
:[MAC Address]:[Friendly Name].toString
in interface Connection
toString
in class Object
Connection.toString()
public String getSimpleConnectionName()
Connection.getSimpleConnectionName()
public String getMACAddress()
public String getFriendlyName()
© 2015 ZIH Corp. All Rights Reserved.