Android: Bluetooth printing

I got the solution of my problem...

if i want to print data more than one time then you dont need to create new Socket Connection with the device... instead call outputstream.write(bytes) method.

and in the end if you want to disconnect device then call mBTScoket.close() method to disconnect device.


You can use printooth library for any printer, printooth is simple and well documented, https://github.com/mazenrashed/Printooth

var printables = ArrayList<Printable>()
var printable = Printable.PrintableBuilder()  
    .setText("Hello World") //The text you want to print
    .setAlignment(DefaultPrinter.ALLIGMENT_CENTER)
    .setEmphasizedMode(DefaultPrinter.EMPHASISED_MODE_BOLD) //Bold or normal  
    .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
    .setUnderlined(DefaultPrinter.UNDELINED_MODE_ON) // Underline on/off
    .setCharacterCode(DefaultPrinter.CHARACTER_CODE_USA_CP437) // Character code to support languages
    .setLineSpacing(DefaultPrinter.LINE_SPACING_60)
    .setNewLinesAfter(1) // To provide n lines after sentence
    .build()
printables.add(printable)
BluetoothPrinter.printer().print(printables)