Skip to content

Printing images across Android app boundaries on POS hardware

Abdul-Qudus Rufai 1 min read

While building the POS integration for some of the field apps I worked on, I ran into one of those problems that looked like it should take 10 minutes, and ended up taking most of the day.

Coming from a previous POS integration where the native side accepted a base64-encoded image, I assumed this would work the same way. So I encoded the image, passed the string to Bitmap, sent the print job, and the app kept crashing because it couldn’t handle the image format.

After digging around, I found out that Bitmap wasn’t expecting image data at all. It was expecting a file path. So I wrote the image to my app’s cache directory using Expo FileSystem and passed that path instead. The app still crashed.

That led to the actual issue. The printing wasn’t happening inside my app. The print request was being handed off to a separate app on the POS, which runs separately from mine. So even though the file existed, the other app couldn’t access a file sitting inside my app’s sandbox.

The fix was to write the composed image to shared media storage using expo-media-library, pass that path to the POS app, and then clean up the temporary file after the print job completed, so the images don’t keep taking up storage.

Beyond getting the printer to finally work, I came away with a much better understanding of how Android handles files and storage, how images are represented and moved around, and what happens when you’re passing things between your app and a native Android app.

Definitely one of those frustrating problems that ended up teaching me a lot.

Originally shared on LinkedIn.

Read the Oyo State field systems case study