The smartphone is microcontroller with a bunch of juicy built in hardware, so I should be able to replicate a lot of my Arduino projects on the Android platform. The goal of this post is to make a "Hello World" on my actual phone in my actual hand. From there I will move on to controlling hardware in later posts. This should serve as a good way to control and interact with the widgets I build.
The future is that we will all carry a device to interface to the world. I'm going to have to get on board. If I succeed maybe this will encourage other hardware heads to try writing apps. Or this will sedate me into a coma in which case my blog will stop.
I have an Android phone, because I have one, and all the Android software is free and the market is open source. My love is for electronics and hardware, not software, and I'm never going to go full hog as a software app developer. It's just too boring. Also, judging from the number of apps out there, it is hard to do something everyone else already hasn't done. However I have an idea for an app that I haven't seen anyone else do yet. That may be because the hardware can't hack it. I'll find out. That is for later, for now, make the phone do something. Anything.
I attempted this once before and crashed and burned with the versions I used and had lots of mysterious errors. Here we go again, this time I'm not trying to outsmart the default installs. The issue I had before is that books and web sites are out of date on the releases and the buttons they describe are never as they say they are. It takes a bit of translation and imagination to follow instructions.
Found the basics of what to do
Of course the android.com site had the same basic info
Side note ... found another development program I may try that may save some code writing. Just noting it for later. http://www.appinventorbeta.com/about/. I didn't try it.
Download and install the developer software
As of 12/27/2011, these were the versions I used:
Decided to use Eclipse 64 bit, downloaded here:
Downloaded, unzipped the files and clicked on "eclipse.exe", it complains it needs Java.
Downloaded Java SE 7u2 JDK here, Windows x64
clicked on the file and installed the development kit.
Started Eclipse again, no errors this time!
Downloaded the SDK here using the windows installer link
It found Java and did the default install, SD manager popped up and I installed everything that looked relevant.
Making note of the install directory
C:\Program Files (x86)\Android\android-sdk
In order to install the Android development tools (ADT)
Started Eclipse -> Help -> Install Software,
Clicked on Available software sites link
Add this (from the instructions)
Click on it, close the sites list and wait for the list to load
check the box for "Developer Tools", in the list (Expand and you see android) then Next
Restarted Eclipse as required
Next set up the launch configuration to say what device I'm emulating.
In EclipseRun->Run Configurations Select Android Application from the list and press the cleverly disguised New button in the upper leftBrowse for your recently created projectEnter a name for the configuration. I chose "moto droid2"Poked around on the Target tab , hit Run
"Your project contains errors" R cannot be resolved to a variable.What is going on?
Ran the emulator and ran an app
Get the Hardware set up to use the real phone
Now the next step is to upload it to the phone and prove I can write a app. Back to some web surfing.
1) Set up the phone for development mode
http://stackoverflow.com/questions/2664425/how-to-test-my-app-on-my-phone-i-have-eclipse-w-android-plug-in tells me:
If you have eclipse with the Android plug-in, all you need to do is go into the settings of the phone (the actual phone in your hand), then applications, then development. Set the Debug mode to on. when you compile the app with eclipse I guess it looks for an actual phone first, if it detects it, then it loads the app on it. If no phone is detected and you have the ADV set up right it loads it there. Easy...
When you select "run" from eclipse, and you have your droid plugged in, it should give you the option to select which device you want to execute the code on. Double clicking on your droid will automatically install and launch the app. You may need to enable the development settings within the Settings menu though for it to be recognized. To confirm that eclipse (really it's adb) can see your droid, launch a terminal or command prompt and type adb devices while the droid is connected. If it's listed there, you're good to goSet up the phone for debug as it says, Still didn't work. No sign that eclipse can see my phone plugged in via the usb cable. I can see the phone's disk from the computer but maybe I have USB in the wrong mode. Figuring out that next.
2) Install the development USB driver on your Windows computer
I think need to install the windows adb driver for my phone on my computer. You need a special USB driver for developers.
Clicked on Handset USB Driver for Windows 64 bit, had to register and all that junk
Downloaded, installed Motorola Mobile Drivers Installation 5.2.0
3) Verify that you can see the phone from the computer
Reading the http://developer.android.com/guide/developing/device.html site again, I got some more info on how to run "adb devices".
You can verify that your device is connected by executingTurns out you run this in a command window on the windows box, after you cd over to the directory where the android sdk is installed. Ran it there. Duh. Here you see the command running for me.
adb devicesfrom your SDK
platform-tools/directory. If connected, you'll see the device name listed as a "device."
4) Set Eclipse to target the phone as an option
Looks like it sees the phone! I can turn of the emulator and the other long number device stays.
However I still don't get the option to Run the program on the real device. Turns out I had to go back to the Run->Configurations and set the target to "Manual" instead of automatic. Now that the driver is installed I get the choice to run on the phone after I hit Run.
Here is the app running on my phone. It was a pain to get these photos because I use my phone to take all the pictures in this blog. So I won't be photographing the phone very much ;-). You can see the app running with the mysterious "Siliconfish there, you Activity" message.
Here is the app showing up on the menu, in the middle right is "Siliconfish App".
I'll save publishing to the Android market until I have something that is worth sharing. But here I have shown how you can make an app for free and put it on your phone in about 6-8 hours of web surfing. Granted I did not program anything, just changed a word or two in a sample program, but this is sure to impress your friends anyway. It took me two tries, this was the second. On the first I never got to the point of launching the emulator because I had so many mysterious errors due to bad versions and botched installations. Just go with the defaults and you will be fine.
The next post goal will be to develop a "Blink" application that flashes a light on the phone. Blink is the "Hello World" of the hardware engineer.