简体   繁体   中英

How can i print to thermal bluetooth printer?

I develop a mobile point of sale with flutter, but I don't know how to print the receipt on a Bluetooth thermal printer

I currently develop a plugin for it but it doesn't work yet

protected void printBill() {
       if(btsocket == null){
          btsocket = DeviceList.getSocket();
          Intent BTIntent = new Intent(getApplicationContext(),        DeviceList.class);
          this.startActivityForResult(BTIntent, DeviceList.REQUEST_CONNECT_BT);
        Toast.makeText(activity,"tes",Toast.LENGTH_LONG).show();
    }
    else{
        OutputStream opstream = null;
        try {
            opstream = btsocket.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        outputStream = opstream;

        //print command
        try {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            outputStream = btsocket.getOutputStream();
            byte[] printformat = new byte[]{0x1B,0x21,0x03};
            outputStream.write(printformat);


            printCustom("Fair Group BD",2,1);
            printCustom("Pepperoni Foods Ltd.",0,1);
            printCustom("H-123, R-123, Dhanmondi, Dhaka-1212",0,1);
            printCustom("Hot Line: +88000 000000",0,1);
            printCustom("Vat Reg : 0000000000,Mushak : 11",0,1);
            String dateTime[] = getDateTime();
            printText(leftRightAlign(dateTime[0], dateTime[1]));
            printText(leftRightAlign("Qty: Name" , "Price "));
            printCustom(new String(new char[32]).replace("\0", "."),0,1);
            printText(leftRightAlign("Total" , "2,0000/="));
            printNewLine();
            printCustom("Thank you for coming & we look",0,1);
            printCustom("forward to serve you again",0,1);
            printNewLine();
            printNewLine();

            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

The source code can be found here

Please help me develop this plugin, at least it can print text

I finally created my own plugin

https://pub.dev/packages/blue_thermal_printer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM