public class BluetoothStatusConnectionInsecure extends BluetoothStatusConnection
BluetoothConnection
. Insecure Bluetooth® connections do not require the device and the printer to be
paired.
package test.zebra.android.comm.examples;
import android.os.Looper;
import com.zebra.sdk.comm.BluetoothStatusConnectionInsecure;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.printer.SGD;
public class BluetoothStatusConnectionInsecureExample {
public static void main(String[] args) {
BluetoothStatusConnectionInsecureExample example = new BluetoothStatusConnectionInsecureExample();
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 insecure connection for given Bluetooth® MAC Address.
Connection thePrinterConn = new BluetoothStatusConnectionInsecure(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 insecure connection to release resources.
thePrinterConn.close();
Looper.myLooper().quit();
} catch (Exception e) {
// Handle communications error here.
e.printStackTrace();
}
}
}).start();
}
}
Constructor and Description |
---|
BluetoothStatusConnectionInsecure(String macAddress)
Constructs a new status only insecure Bluetooth® connection with the given
macAddress . |
BluetoothStatusConnectionInsecure(String macAddress,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Constructs a new status only insecure Bluetooth® connection with the given
macAddress and
timeout values. |
close, getFriendlyName, getMACAddress, getSimpleConnectionName, open, toString
addWriteLogStream, bytesAvailable, getConnectionReestablisher, getManufacturer, getMaxDataToWrite, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, read, read, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxDataToWrite, setMaxTimeoutForRead, setReadTimeout, setTimeToWaitForMoreData, waitForData, write, write, write
addWriteLogStream
bytesAvailable, getConnectionReestablisher, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write, write, write
public BluetoothStatusConnectionInsecure(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.BluetoothStatusConnectionInsecure(String, int, int)
.macAddress
- the device's MAC address.public BluetoothStatusConnectionInsecure(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.
© 2017 ZIH Corp. All Rights Reserved.