Archive for the ‘Android’ Category.

android: ipPrint4 print label/receipts to ip printer

ipPrint4

An android label/receipt printing app for TCP/IP connected printers

This app is based on my btPrint4 app. In contrast to btPrint4 this time we print on TCP/IP connected printers to port 9100.

As with btPrint4 we have a main activity and one to list available printers and one to list available demo files.

ipprint4_main pb31

The challenge with ipPrint4 was a replacement for the bluetooth device discovery. This time we have to scan TCP/IP address range for port 9100. This port is also called HP direct printing port and supported by many printers. It behaves similar to telnet and you can just send print commands to the interface.

The second main change to btPrint4 was the printing code. This time we do not have to use a bluetooth socket but a network TCP/IP socket.

A TCP/IP portscanner

If you scan a range of IP addresses in sequence and try to open a port with a timeout of, let’s say 200ms, the scan will take (200msx254, scan from 1 to 254) 50 seconds.

Port scan code Continue reading ‘android: ipPrint4 print label/receipts to ip printer’ »

Android development: a Bluetooth label/receipt printing demo

BtPrint4

A Bluetooth Label printer demo

This is my first Android project and I had to learn how to get an Android activity working. I am a Windows Mobile C# developer and had to learn that you have to do many handwritten code in compare to what Visual Studio for SmartDevice development does automatically.

An Android activity consists of many, many files with references to each other. Fortunately an IDE helps you creating and finding all the files and references.

I started with Eclipse and ADT but went over to use Android Studio. Eclipse showed very strange behaving when designing the GUI of my activities.

functions

To print to a bluetooth printer we need several functions:

  • A reference to the printer, the BT MAC address
  • A socket to communicate with the printer
  • A set of demo data

Make the activity more user friendly

  • provide a list of Bluetooth devices nearby to be used as target
  • move the communication part to a background thread
  • a list with demo data

implementation

The UI has an EditText holding the BT MAC address and a TextView to hold the demo data reference. Buttons for BT discovery, Connect/Disconnect, Demo select and a Print button. There are two list activities (separate windows or forms): the BT device list and a demo data list. The BT MAC address is filled either manually or by selecting a BT device from the list.

btprint4_main

I always try to keep code re-useable and so I implemented some helper classes. Continue reading ‘Android development: a Bluetooth label/receipt printing demo’ »