I am working out how to incorporate Zebra's mobile printer sdk for android into Basic4Android (which I will happily provide as open code for others to use).
The simple library example from Basic4Android generates a wrapper for a function, however I really want to provide access to the library classes that enables a bluetooth connection object to the mobile printer.
The std code it uses for connection is given below of which I would like to use the sendCpclOverBluetooth member function
Can I easily put a wrapper in eclipse around the BluetoothPrinterConnection object which i will modify to accept additional input parameters to support what I want to print?
Are there any tutorials/examples on creating libraries like this? i.e. objects rather than functions.
thanks, Anton
The simple library example from Basic4Android generates a wrapper for a function, however I really want to provide access to the library classes that enables a bluetooth connection object to the mobile printer.
The std code it uses for connection is given below of which I would like to use the sendCpclOverBluetooth member function
Can I easily put a wrapper in eclipse around the BluetoothPrinterConnection object which i will modify to accept additional input parameters to support what I want to print?
Are there any tutorials/examples on creating libraries like this? i.e. objects rather than functions.
thanks, Anton
B4X:
public class BluetoothPrinterConnection
extends ZebraPrinterConnectionA
Establishes a Bluetooth® connection to a printer
import com.zebra.android.comm.ZebraPrinterConnection;
import com.zebra.android.comm.ZebraPrinterConnectionException;
import com.zebra.android.comm.BluetoothPrinterConnection;
private void sendZplOverBluetooth(final String theBtMacAddress) {
new Thread(new Runnable() {
public void run() {
try {
// Instantiate connection for given Bluetooth® MAC Address.
ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection(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 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 connection for given Bluetooth® MAC Address.
ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection(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 connection to release resources.
thePrinterConn.close();
Looper.myLooper().quit();
} catch (Exception e) {
// Handle communications error here.
e.printStackTrace();
}
}
}).start();
}