'How to connect a mobile and a printer via bluetooth in android?

Can anyone tell me how to connect a mobile and a printer via bluetooth to print a text file in android?

That is,if i click the print button from the android application,the printer has to print that corresponding file.As per my knowledge i have searched for it in Google, but i couldn't find any good samples to do it.Has anyone have at-least one sample android program to do this, it will be better to clear my chaos.

Suggestions please. Thanks for your precious time!..



Solution 1:[1]

You can use this awesome lib, you can connect to any printer and print easily,

https://github.com/mazenrashed/Printooth

you can download it by:

implementation 'com.github.mazenrashed:Printooth:${LAST_VERSION}'

and use it like:

var printables = ArrayList<Printable>()
var printable = Printable.PrintableBuilder()  
.setText("Hello World")

printables.add(printable)

BluetoothPrinter.printer().print(printables)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mazen Rashed