Application Development on Android Phones

quantityforeheadMobile - Wireless

Dec 10, 2013 (3 years and 6 months ago)

66 views

Application Development on Android Phones
Courtesy: Trisha Biswas
A. First steps with the Droid phone
1. Plug in the battery
2. Turn the phone on using the power switch
3. When prompted to activate phone, use the following code to bypass activation:
a. With the picture of the green android on the screen, tap the upper-left, upper-right, bottom-
right, bottom-left corners of the black screen. Nothing will happen on each tap, but on the last
one, it will go to the main screen
b. Every boot after that, you just hit the Home button to bypass activation
4. If prompted to set up a Google account, “skip”. You should be able to see the ‘desktop’ now
5. Turn on "USB Debugging" on your device. Go to Settings > Applications > Development >
USB Debugging ON
6. Learn the basics of Android development from:
http://developer.android.com/guide/basics/what-is-android.html
B. Setting up the Android SDK and NDK environment for programming
1. Download the Android SDK from http://developer.android.com/sdk/index.html
2. Unzip the SDK in your computer (Let the directory name be Android/SDK)
3. Add the location of the SDK’s ‘tools’ directory in your system PATH
4. Install the Eclipse IDE from http://www.eclipse.org/downloads/
If you already have Eclipse, make sure it is an updated version
5. Install the ADT Plugin by going to Help > Software Updates in Eclipse, and clicking the
Available Software tab. Add site https://dl-ssl.google.com/android/eclipse/ and install the ADT
Plugin from the list of available software. When completed, restart Eclipse.
More information can be found at:
http://developer.android.com/intl/de/sdk/eclipse-adt.html
6. Configure the ADT Plugin by going to Windows > Preferences > Android and then setting the
SDK location. Click Apply and OK
7. Install the version of the SDK that you are going to use. The Moto Droid supports up to
version 2.1 of the SDK, API level 7, so you are suggested to use that. To install the correct SDK,
navigate to Window > Android SDK and AVD Manager > Available Software. Add site:
https://dl-ssl.google.com/android/eclipse/ and install ‘Android 2.1 –update 1, - API level 7’.
Optionally, you can also install ‘Google APIs version 7’ and ‘Samples for SDK, API 7’
8. Download the Android NDK from http://developer.android.com/sdk/ndk/index.html
9. Unzip the NDK in your computer (Let the directory name be Android/NDK). Read the
INSTALL.TXT in Android/NDK/docs
Note: Ensure that the NDK directory is one where you have read/write access. Avoid system
directories such as C:\Program Files (in Windows)
10. You will need gcc and GNU make to build the NDK shared libraries. For Windows, install
Cygwin with gcc and make tools from: http://www.cygwin.com/
11. For NDK releases prior to 4, go to the NDK root directory and run ./build/host-setup.sh
If you just downloaded the NDK, skip this step
C. Writing, Building and Running an SDK Application
1. Open Eclipse. Choose a workspace corresponding to the location of the project
2. To create a new project, go to File > New > Android Project. Enter the project name, package
name, build target and click ‘Finish’. From here on, we’ll call this top level project directory as
<project>
3. To open an existing project go to File > Import > General > Existing Projects into Workspace.
Then browse to root directory of the project and click ‘Finish’
4. In a typical project, you would need to add your code to the ‘src’ folder, and the ‘res’ folder.
The ‘res’ or resources folder contains the layouts for each view of your project (written in XML)
as well as all pictures / icons etc. The ‘src’ contains the source code in Java. The source code
links the XML view with the backend. For example, if the XML layout has a button called
‘okay’, the Java source code specifies the result of clicking the ‘okay’ button. Each view of your
project in an Android application is called an activity.
5. Please refer to the following links for information on Activities, Services and Broadcast
Receivers in Android: http://developer.android.com/guide/topics/fundamentals.html
6. To learn about UI development, refer to:
http://developer.android.com/guide/topics/ui/index.html
7. Use the Dev Guide on the Android Developers site extensively, for a detailed overview of
Android applications. Use the reference section to find out about specific Java libraries for the
Android

EXERCISE 1: Develop a simple Hello World Application using the SDK.

8. Before running your application, create an Android Virtual Device (AVD) by going to
Window > Android SDK and AVD Manager > Virtual Devices. Create a new AVD based on the
API level of your project. The Motorola Droid runs SDK Platform 2.1, API 7, so you are
suggested to set up an AVD with the target as ‘Android 2.1 –update 1, - API level 7’
9. The above target won’t show up on the drop-down list, if you don’t have the correct SDK
version installed. To check, click on ‘Installed Packages’ in Android SDK and AVD Manager. If
the package is not installed, click ‘Available Packages’ and choose the correct package to install
10. Make sure the project is also configured for the correct build target. Right click on project
name > Properties. Choose the build target ‘Android 2.1’
11. In AndroidManifest.xml, the API level should be specified correctly, i.e., you should have a
line that says: <uses-sdk android:minSdkVersion="7" />
12. To run your application, right-click on the project name, click Run As > Android
Application. The emulator should open up, with your application. (It takes a while to open up the
emulator, so give it some time)
D. Running an application on the Droid phone
(Part of this information was provided by Dr. Sarah Heckman)
1. Set up the phone for debugging as mentioned in A.5
2. Declare your application as "debuggable" in your Android Manifest. In Eclipse, you can do
this from the Application tab when viewing the Manifest (on the right side, set Debuggable to
true). Otherwise, in the AndroidManifest.xml file, add android:debuggable="true" to the
<application> element
3. Setup your system to detect your device.
a. If you're developing on Windows (32-bit only), you need to install the USB driver for adb:
i. Download the driver ZIP file from:
http://developer.android.com/intl/de/sdk/win-usb.html) and unzip it
ii. Connect your Android device via USB. When the Found New Hardware Wizard appears,
you'll be asked if you'd like Windows Update to search for software, select No, not this time and
click Next
iii. Select Install from a list or specified location and click Next
iv. Select Search for the best driver in these locations. Browse and select the unzipped file
v. Click Finish
vi. If Found New Hardware Wizard does not appear, go to Device Manager and look for any
unknown device (it will probably be called MotorolaXXX). Un-install the device, disconnect it,
reconnect it, and manually install the driver. The driver can be found from the location where
you unzipped it. Again disconnect the phone, restart your computer and reconnect the phone. It
should now be connected
b. If you're developing on Mac OS X, skip this step
c. If you're developing on Ubuntu Linux, you need to add a rules file:
i. Login as root and create this file:
/etc/udev/rules.d/50-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"
ii. Now execute: chmod a+rx /etc/udev/rules.d/50-android.rules
4. To verify that your device is connected properly, type ‘abd devices’ on the console. Your
Android device should show up in the list of devices
5. Using Eclipse, select run or debug as usual. If you have an emulator running, then you will be
presented with a Device Chooser dialog that lists the emulator(s) running and the connected
device(s). Otherwise, the device will be used by default, instead of launching a new emulator
6. If the application does not get installed on the device, try deleting all the AVDs and then
running it from Eclipse. Note that steps C.10 – C.12 must be carried out to run and install the
application on the phone
7. In addition to that, you may also need to mount the device on the computer. To do this, pull
down the top notification bar from the ‘desktop’ of the phone. If the phone is connected, then
you should be able to see ‘USB Connected’. Press ‘USB Connected’ > Mount
8. For more information, please refer to
http://developer.android.com/guide/developing/device.html
E. Writing and Compiling an NDK Application
1. Refer to OVERVIEW.TXT in Android/NDK/docs
2. Store your native code in <project>/jni. Create the directory if it is not there
3. Write <project>/jni/Android.mk to describe your sources to the NDK build system
4. Write <project>/jni/Application.mk to describe your application and the native sources it
needs to the NDK build system. This step is optional. (For releases prior to 4, put the
Application.mk in apps/<myapp>/)
5. Build your native code by running "<ndk>/ndk-build" from your <project> directory, where
<ndk> is the entire path to NDK.
6. For releases prior to 4, build your native code by running “make APP=<myapp>” in the top
level NDK directory
7. Build the Android application from Eclipse as usual, by clicking Project > Run As > Android
Application
8. Use the sample applications in Android/NDK/apps to get an idea of native code development
F. Enabling Ad-hoc wifi on your Droid
To make two phones (say, A and B) connect to each other via ad-hoc wifi network, we need to do the
following:

On phone A:

1. Connect to the Internet via wifi (e.g. the ncsu wifi network).
2. Install "Astro File Manager" and "Android Terminal Emulator" from android market.
3. If you have Android 2.0.1 (which is the firmware of the Droid by default), open the browser and
download wimervision.com/android/root/update.zip and follow the instructions here
(http://www.youtube.com/watch?v=pRFjA2HD2Hg) to root your Droid.
4. If you have updated your phone with Android 2.2 follow the instructions at http://www.droid-
life.com/2010/09/09/how-to-root-motorola-droid-running-android-2-2-frg22d/ to root your Droid.
5. Install "Wireless Tether for Root Users" from android market.
6. Start the tethering application (ignore the warning that netfilter is not available).
7. Now phone A is advertising an ad-hoc wifi network with SSID "AndroidTether". Its own IP is
192.168.2.254 by default and it also acts as a DHCP server.

On phone B:

1. Follow step 1-4 of phone A to root the phone.
2. Install "ROM Manager" from android market.
3. Launch ROM Manager, choose the first option in the app: "Flash ClockworkMod Recovery" to update
to the latest version.
4. Select the Download ROM option from the main menu in the ROM Manager. Select CyanogenMod,
and then choose version 6.0.0. Check the Google Apps option when prompted.
5. Once the ROM finishes downloading, it asks if you would like to Backup Existing ROM and Wipe
Data and Cache. Check both options.
6. If Superuser prompts for root permissions, check Remember and then Allow.
7. The Motorola Droid will now reboot into recovery, wipe data and cache, and then install
CyanogenMod. When it's finished installing it will reboot into CyanogenMod.
8. Now go to "Settings" -> "Wireless & networks" -> "Wi-Fi settings" and turn on wifi. The phone will
scan for available networks.
9. You should be able to see the "AndroidTether" ad-hoc network advertised by phone A. Connect to it
and you are done!
10. To verify the connection, open the terminal emulator and type "netcfg". You will find your IP address
on the line starting with "tiwlan0". You should get an IP like 192.168.2.100. You can ping phone
A at 192.168.2.254. Phone A can also ping phone B.

To make a 3rd, 4th, ... phone connect to the ad-hoc network, follow
the instructions for phone B.

EXERCISE 2: Develop a simple client-server application using Java socket library and
demonstrate it on two droids using ad-hoc network