Controlling Your Android Device via ADB and a USB Connection

Photo 1

Now that you’ve got your development environment setup, you need to be able to connect your Android powered device to your computer.  This will allow you to install .apk files from your computer to the device, copy files to and from the SD card, input commands from a terminal window to the phone, and many more useful things.  This is imperative if you plan on programming for your Android device, or plan on doing some custom things to your device, such as rooting the device, modifying system files on the device, etc.

The following instructions assume you’ve downloaded and installed the Android SDK, and added the /tools directory to your system’s $PATH variable.  For instructions on how to do this, see my earlier post Installing Android 2.0 SDK on a Mac.

Step one: Enable debugging on your Android device

From the home screen press the menu button

Settings > Applications > Development > USB Debugging

Step two: Connect your device to computer

I’m going to assume you know how to do this.  From several posts I’ve seen online, Macs will only recognize the device if it is connected to a USB 2.0 hub.

Step three: Jump though hoops to make your computer recognize your Android device

This step depends on the operating system you have.  I have experience with Mac and linux development environments, so I’m going to provide the most detail about those.  Instructions on how to get Windows machines to recognize your device can be found here.  Essentially you have to install a driver to get your Android device and your windows machine working together peacefully.

Mac

Adb just works.  Test to make sure your device is working by typing adb devices into a terminal window.  Your device should be listed here.  If not, restart the phone and the adb service and reconnect you device and computer.

Ubuntu Linux

This is going to require a little prodding to get to work.

  1. Open a terminal and enter superuser mode (enter su and then your root password)
  2. Create the file /etc/udev/rules.d/51-android.rules. I use nano for this purpose by the following command: nano /etc/udev/rules.d/51-android.rules
  3. Based on the distro you’re running edit the file:
    1. For Gusty/Hardy/Intrepid/Jackalope/Koala, edit the file to read:
      SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
    2. For Gusty/Hardy, edit the file to read:
      SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
  4. Close editor and cd into directory where you made the file (/etc/udev/rules.d/)
  5. Enter the following command: chmod a+r /etc/udev/rules.d/51-android.rules

If you’re developing on Ubuntu Linux, you need to add a rules file that contains a USB configuration for each type of device you want to use for development. Each device manufacturer uses a different vendor ID. The example rules files below show how to add an entry for a single vendor ID (the HTC vendor ID). In order to support more devices, you will need additional lines of the same format that provide a different value for the SYSFS{idVendor} property. For other IDs, see the table of USB Vendor IDs, below.

1. Log in as root and create this file: /etc/udev/rules.d/51-android.rules.

For Gusty/Hardy, edit the file to read:
SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″

For Dapper, edit the file to read:
SUBSYSTEM==”usb_device”, SYSFS{idVendor}==”0bb4″, MODE=”0666″

Where idVendor is the 4 charachter code associated with the manufacturer of your device in the following list:

Acer : 0502

HTC : 0bb4

Huawei : 12d1

LG : 1004

Motorola : 22b8

Samsung : 04e8

Sony Ericsson : 0fce

2. Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules

After a quick restart of adb (by issuing the command adb kill-server and then any other adb command afterwards) your phone should appear.  If not, then restart the phone along with running adb kill-server and then try adb devices.  Your phone should appear in the list of devices then.

Hope this helps.  Soon you’ll be ready to unleash the full power of Android!

Open a terminal and enter superuser mode (enter su and then your root password); Create the file /etc/udev/rules.d/51-android.rules. I use nano for this purpose by the following command: nano /etc/udev/rules.d/51-android.rules


DroidWeb – http://www.blog.droidweb.com/

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image