public class BluetoothConnectionInsecure extends BluetoothConnection
package test.zebra.android.comm.examples;
import android.os.Looper;
import com.zebra.sdk.comm.BluetoothConnectionInsecure;
import com.zebra.sdk.comm.Connection;
public class BluetoothConnectionInsecureExample {
public static void main(String[] args) {
BluetoothConnectionInsecureExample example = new BluetoothConnectionInsecureExample();
String theBtMacAddress = "00:11:BB:DD:55:FF";
example.sendZplOverBluetooth(theBtMacAddress);
example.sendCpclOverBluetooth(theBtMacAddress);
}
private void sendZplOverBluetooth(final String theBtMacAddress) {
new Thread(new Runnable() {
public void run() {
try {
// Instantiate insecure connection for given Bluetooth® MAC Address.
Connection thePrinterConn = new BluetoothConnectionInsecure(theBtMacAddress);
// Initialize
Looper.prepare();
// Open the connection - physical connection is established here.
thePrinterConn.open();
// This example prints "This is a ZPL test." near the top of the label.
String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
// Send the data to printer as a byte array.
thePrinterConn.write(zplData.getBytes());
// Make sure the data got to the printer before closing the connection
Thread.sleep(500);
// Close the insecure connection to release resources.
thePrinterConn.close();
Looper.myLooper().quit();
} catch (Exception e) {
// Handle communications error here.
e.printStackTrace();
}
}
}).start();
}
private void sendCpclOverBluetooth(final String theBtMacAddress) {
new Thread(new Runnable() {
public void run() {
try {
// Instantiate insecure connection for given Bluetooth® MAC Address.
Connection thePrinterConn = new BluetoothConnectionInsecure(theBtMacAddress);
// Initialize
Looper.prepare();
// Open the connection - physical connection is established here.
thePrinterConn.open();
// This example prints "This is a CPCL test." near the top of the label.
String cpclData = "! 0 200 200 210 1\r\n"
+ "TEXT 4 0 30 40 This is a CPCL test.\r\n"
+ "FORM\r\n"
+ "PRINT\r\n";
// Send the data to printer as a byte array.
thePrinterConn.write(cpclData.getBytes());
// Make sure the data got to the printer before closing the connection
Thread.sleep(500);
// 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 |
---|
BluetoothConnectionInsecure(String macAddress)
Constructs a new insecure Bluetooth® connection with the given
macAddress . |
BluetoothConnectionInsecure(String macAddress,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Constructs a new insecure Bluetooth® connection with the given
macAddress and timeout values. |
close, getConnectionReestablisher, getFriendlyName, getMACAddress, getSimpleConnectionName, open, toString
bytesAvailable, getMaxTimeoutForRead, getTimeToWaitForMoreData, isConnected, read, read, readChar, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write, write, write
public BluetoothConnectionInsecure(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.BluetoothConnectionInsecure(String, int, int)
.macAddress
- the device's MAC address.public BluetoothConnectionInsecure(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.
© 2015 ZIH Corp. All Rights Reserved.