I got some sample code in Java does anyone want to wrap it for me
import com.sunmi.peripheral.printer.InnerPrinterCallback;
import com.sunmi.peripheral.printer.InnerPrinterException;
import com.sunmi.peripheral.printer.InnerPrinterManager;
import com.sunmi.peripheral.printer.InnerResultCallback;
import com.sunmi.peripheral.printer.SunmiPrinterService;
public class Printer {
private static String TAG = "Printer";
private String printerExceptionMessage;
private String lastFunctionProcessed;
private SunmiPrinterService mSunmiPrinterService;
public int init(Context context) {
try {
boolean result = InnerPrinterManager.getInstance().bindService(context, innerPrinterCallback);
} catch (InnerPrinterException e) {
Log.e(TAG, "Printer initialise error: " + e);
return -1;
}
return 0;
}
private InnerPrinterCallback innerPrinterCallback = new InnerPrinterCallback() {
@override
protected void onConnected(SunmiPrinterService service) {
Log.i(TAG, "Printer connected");
mSunmiPrinterService = service;
}
@override
protected void onDisconnected() {
Log.i(TAG, "Printer disconnected");
}
};
private InnerResultCallback printFinishedCallback = new InnerResultCallback() {
@override
public void onRunResult(boolean isSuccess) throws RemoteException {
Log.i(TAG, "printFinishedCallback: onRunResult=" + isSuccess);
}
@override
public void onReturnString(String result) throws RemoteException {
Log.i(TAG, "printFinishedCallback: onReturnString=" + result);
}
@override
public void onRaiseException(int code, String msg) throws RemoteException {
Log.i(TAG, "printFinishedCallback: onRaiseException=" + msg);
}
@override
public void onPrintResult(int code, String msg) throws RemoteException {
Log.i(TAG, "printFinishedCallback: onPrintResult=" + msg);
}
};
private InnerResultCallback printResultCallback = new InnerResultCallback() {
@override
public void onRunResult(boolean isSuccess) throws RemoteException {
Log.i(TAG, "printResultCallback: onRunResult = " + isSuccess);
}
@override
public void onReturnString(String result) throws RemoteException {
Log.i(TAG, "printResultCallback: onReturnString = " + result);
}
@override
public void onRaiseException(int code, String msg) throws RemoteException {
Log.i(TAG, "printResultCallback: onRaiseException = " + msg);
printerExceptionMessage = msg;
}
@override
public void onPrintResult(int code, String msg) throws RemoteException {
Log.i(TAG, "printResultCallback: onPrintResult = " + msg);
}
};
public String getPrinterExceptionMessage() {
return printerExceptionMessage;
}
private int getPrinterStatus() {
printerExceptionMessage = "";
if (mSunmiPrinterService == null) {
Log.i(TAG, "Error, mSunmiPrinterService == null");
printerExceptionMessage = "Printer service not initialised";
return -1;
}
try {
int printerStatus = mSunmiPrinterService.updatePrinterState();
Log.i(TAG, "printerStatus=" + printerStatus);
switch (printerStatus) {
case 1: // Normal
case 2: // under preparation
break;
case 3:
printerExceptionMessage = "Printer comms error";
return -2;
case 4:
printerExceptionMessage = "Printer is out of paper";
return -3;
case 5:
printerExceptionMessage = "Printer overheated";
return -4;
case 6:
printerExceptionMessage = "Printer cover open";
return -5;
case 7:
printerExceptionMessage = "Cutter error";
return -6;
case 8: // cutter recovered
case 9: // black mark not detected
break;
case 505:
printerExceptionMessage = "No printer detected";
return -7;
case 507:
printerExceptionMessage = "Printer firmware update failed";
return -8;
}
}
catch (Exception e) {
printerExceptionMessage = e.getMessage();
Log.e(TAG, "getPrinterStatus exception: " + e);
return -10;
}
return 0;
}
public int printBitmap(Bitmap bitmap) {
Log.i(TAG, "printBitmap:" + bitmap.toString());
int printerStatus = getPrinterStatus();
if (printerStatus != 0) return printerStatus;
try {
mSunmiPrinterService.lineWrap(1, printResultCallback);
mSunmiPrinterService.printBitmap(bitmap, printResultCallback);
mSunmiPrinterService.lineWrap(1, printResultCallback);
mSunmiPrinterService.commitPrinterBufferWithCallback(printFinishedCallback);
} catch (RemoteException e) {
Log.e(TAG, "printBitmap Exception:" + e);
return -10;
}
return 0;
}
}