Android ScanAndroid Developer Challenge submission by Jeffrey Sharkey
Scan is an Android application that finds pricing and metadata for anything with a barcode. Here are some key features that make Scan stand out:
- Automatic barcode recognition using onboard phone camera using ZXing
- Shows CD, DVD, or book cover along with detailed reviews from Amazon.com
- Searches over a dozen stores, both online and brick+mortar
- Highlights brick+mortar stores that are nearby, with option to call the store or get directions
- Links to online storefronts to buy online from the phone
- Tracklisting for CDs, along with option to play sample tracks right on phone
- For books, searches local libraries to see if they have a copy
Watch the quick 3-minute video that shows the power of Scan in action with real barcodes:
How do I use Scan?
Well, it's pretty simple really, just point your phone at a barcode and scan it
. You'll probably need to get pretty close to the barcode. Try filling the camera window with the barcode, and make sure you have good light.
If you're running on the emulator, check out the section below for instructions on hooking up a webcam. Once you hit "Scan" the Android will try recognizing the barcode, and will then ask a remote server to gather up metadata and prices about the item you scanned. This will usually take about 15 seconds. When it returns, you'll be shown some metadata about the item
you scanned, mostly for you to verify that we found the correct item online. You'll see reviews from Amazon.com
that you can scroll through and read.
On the "Sellers" tab, you can browse a list of sellers who have the item you scanned. These can range from online stores
like Half.com, to a brick+mortar
Barnes and Noble down the street, to your local library
if they have a copy. Scroll through the list using the arrow keys to pick a store, then tap on "Link" to jump to their website. If it's a brick+mortar store, "Directions" will show driving directions
from your current GPS location and "Call" will call the store's local phone number
The seller list is sorted by price, allowing you to quickly get a gauge of what the item is selling for. If you scanned a CD album, you'll probably see a "Tracks" tab that lists all of the album's tracks
and their play length. If the album is available in the Amazon MP3 store, you'll see a "Play" button which will stream and play a 30-second sample clip
of the track right on your phone
That's the basics of what Scan does. The power lies in the Python backend that does the heavy lifting of searching stores for you. It runs on a remote server to keep phone bandwidth low. You can read more about the server script in a separate section below.
Working with an emulator
So are you stuck with an emulator instead of a real Android phone? You can still get a camera working to scan barcodes, just like we showed in the video. I'm using the approach pioneered by Tom Gibara with his remote camera idea. Essentially you're using the Java Media Framework to latch onto your computer's USB webcam and create a network camera that the Android can hook into and use. I did all of my development on Linux, so the JMF can be a slight pain to get working correctly. In either case, go grab Tom's WebcamBroadcaster class and get it started up on your local computer:
Then connect to the running JMF program from Scan by changing the camera source to "Socket camera (using JMF)" and entering your local IP address. Be sure to use your computer's real IP address, as 127.0.0.1 has a special meaning to the Android emulator. Then click "Save changes" and switch back to the "Scan" tab.
You should now see your webcam live on the Android device. Move around, zoom in on a barcode, and click "Scan" just like you would with a real phone device. You might have trouble with cheap webcams
because the optics aren't detailed enough for Scan to recognize the barcode. If you keep getting barcode recognition errors, try again with a better webcam, or using better lighting.
Using a MiniDV camera
I ran into issues with cheap webcams not providing enough barcode detail, and instead had to use a firewire MiniDV camera as my video source. I did this using the same JMF approach above, except I used a sweet utility called DV4Linux that emulates raw1394 devices as V4L devices. Because the JMF recognizes V4L devices perfectly, I just wrapped my JMF console commands using their utility:
dv4lstart java WebcamBroadcaster
It worked flawlessly, and this is what I used to create the overview video linked earlier. Here's the DV4Linux website with source code:
What is the backend?
Because scraping store APIs can be bandwidth expensive, the actual searching is handled by a separate server written in Python. The Android phone feeds the scanned UPC/ISBN code and a current zipcode to the server, which then feeds back a very condensed
XML response with the essential data. Here's a list of the specific sites/APIs that we scrape:
- UPC Database
- Amazon.com API
- Half.com API
- Yahoo API
- Barnes and Noble (items and store locations)
- Hastings (items and store locations)
- Local libraries (San Francisco, San Jose, Portland)
The Python script will mark any nearby stores or libraries with an address and phone number. For metadata, the script fills in details from any available data source, which means it can still provide answers even if one or more APIs fail.
Where's the source code?
I'll release both the Android and Python server source code once the Android Developer Challenge winners are announced in mid-May. I'll be releasing it under a GPLv3 license.
How is Scan able to play sample music clips?
Scan can play back sample music clips for any album available in the Amazon MP3 store. This feature isn't even provided by Amazon at this point, so we have some pretty sweet screen-scraping going on in the Python backend that digs deep into Amazon to pull out sample clips that can be played easily on the phone.