I go out for beer and supper with my pal, Jim Flanagan, and use what I've learned to explain why his attempt to put a random Java app onto his girlfriend's Android phone failed.
Teaching someone else what I know is a good way to review and uncover what I don't really understand well enough to explain.
"You thought I wanted to put a Java app onto Marcia's phone?" Jim has no idea what I'm talking about.
He has, he explains, read that he can use SL4A and JRuby to run Ruby programs on Android devices. Marcia has an Android phone, and he knows Ruby. A natural match.
He doesn't understand what SL4A is or why it would need JRuby, or, for that matter, even what Sinatra is, which is also required, "... But maybe you do."
Well, no, but at least this time I've paid close enough attention to know what the question is. I've heard of JRuby and Sinatra. SL4A? Nope, but it's "
Scripting Layer For Android."
Jim says that the place he found this information has an example -- only a few lines of code -- that turn an Android phone into a
spy camera. He could install it on Marcia's camera and spy on her from his laptop. Of course, he could just go over and see her whenever he wants, but okay, we're guys, so
spy camera is enough to make this compelling.
After supper, we head back over to Caffe Sole, where they now have a band playing live, bad, jazz.
He shows me the code and yes, just a handful of lines of Ruby, running on the phone, are claimed to tell the camera to take a picture, and then serve the picture up over the internet, on Webrick's port 4567. (Webrick is Ruby's built-in, light-weight web server).
Browsing to that port at the phone's IP address, from any browser, should show the picture. Somehow, the code also lets the laptop instruct the phone when to take pictures.
Only one way to find out.
I google for SL4A from my phone, and
install it from Google Code. SL4A, in turn, lets me install JRuby. The code samples that come with that installation work indifferently. The "Hello, World" app works okay, the app to toggle airplane mode seems to work once, but we can't repeat that.
But who cares about airplane mode if we can have
a Spy Camera?
I connect the phone to his Mac with a USB cable, and the phone asks me if I want to allow him to "Download files via USB."
Well, sure.
After some trial and error, we download the spy-camera app and and associated directory, uh, folder, I poke around, turn on the phone's WiFi, and figure out the phone's IP address: 192.168.1.8. Jim browses to it to 192.168.1.8:4567. The phone's camera makes a loud shutter click.
Actually, that's just Android generating a "shutter-click sound" electronically, since the camera shutter is also entirely electronic, but we'll take it. Houston, we have ignition.
After a couple second or two, a picture appears on Jim's browser. It's almost black. The coffee shop is dark and the pictures are darker. We try a few more. I finally realize I'm trying to take a picture with the phone's rear-facing camera, but it doesn't have one.
I turn the phone around.
I try to take a picture of the woman sitting next to Jim. She says, "Why do you want to take my picture?" turns her head away, and puts up her hand. I bet real spies never have this sort of problem.
I go over to the counter, where the light's better, and take a picture of Katie, the barista. It works! We show her on the laptop. It's sideways, but she's still still pleased.
So are we. We leave the coffee shop in triumph.