Showing posts with label Android Basics. Show all posts
Showing posts with label Android Basics. Show all posts

Thursday, December 15, 2011

Deploying the Application on the Device (Mac or Windows or Linux)


The application is deployed to the Emulator directly from the Eclipse. To deploy the application on the Android powered device, following are the steps:

Declare Application as ‘debuggable’

We will declare our application as ‘debuggable’ in Android Manifest.xml file shown in Fig.1 at position 6 by adding android: debuggable="true" to the <application> element.

Android Device Setup

We will turn on the ‘USB Debugging’ on the device

·      On the device, go to home screen, press MENU then select Application->Development
·      Enable ‘USB Debugging’

System Setup to detect the device

This step varies for different operating systems on which we are developing our application.

Windows

Install a USB driver for adb (Android debug Bridge)

Mac OS

For Mac OS X, skip this step as it works fine.

Ubuntu Linux

In case of Ubuntu Linux, we need to add a rules file that contains a USB configuration for the device (Vendor Id) which we are using for development.

·      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"

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

Run the Application

If you are using Eclipse, then select Eclipse->Run->Run Configurations->Run, in the available Device Chooser dialog that lists the available emulators and connected devices, select the device and click Run

If you are using command line, then open the cmd window and run the following command to run the application
C:\[path_to_adb_tool] > adb install [path_to_apk]\ [appname].apk

Enjoy your application watching at your mobile J

Wednesday, December 14, 2011

How to create Android Application?


The Android SDK provides the tools and APIs necessary to develop applications on the Android platform using the Java programming language. To start with Android application development, the developer needs to have elementary knowledge of Java and XML.
Well, starting with the creation of first android application,
a)    Select Eclipse->File->New->Android Project, in the dialog, fill the fields, Project Name (ex: MyFirstApp), Build  Target (to compile the application by a particular Android SDK), Application Name (name of application, ex:      MyFirstApp), Package Name (ex: com.myapp), Create Activity (ex: MyFirstActivity)
   b)       Click on Next->Finish. An android project folder with
           Name ‘MyFirstApp’ will get built in the left pane (Project Explorer) of Eclipse.
   c)       On exploring the Project folder, you will be able to see the sub folders /src, /gen, /res & AndroidManifest.xml as shown in the below image at positions 1, 2, 4 and 6 respectively.




There are four building blocks to build an Android Application- Activity file, R.java, Resource files and Android Manifest file as shown in above image at positions 1, 3, 4, 6 respectively. Activity files are used to write the Business logic of action happening on the Android Screen. The resource files are used to create the layouts for the screen. The Android Manifest file presents the essential information about the application to the Android OS, like- version, icon, activities and permissions given to application, which Android requires before running any application. R.java file does the mapping between layout files and Activity file.


Activity File

  • Edit MyFirstActivity.java in the package com.myapp (at position 1) as the code shown in the above image.
  • Next, the Emulator is required to see the output screen. Following are the steps to create emulator:
  • Select Eclipse->Window->Android SDK and AVD Manager. In the available dialog, select Virtual devices >New.
  • In the available dialog, enter the name of emulator (ex: MyDevice) and select the target API (Android version)for the emulator. Now click on Create AVD button.
  • The emulator with name ‘MyDevice’ will be added in the list of existing emulators (if any) on the previous dialog and to start the emulator select Start from the dialog.
  • To run the application, select Eclipse->Run->Run Configurations.
  • In the available dialog click on Run and see the log in the console window of the Eclipse.
The eclipse itself installs the application on the Android Emulator and the output can be seen in the Android Emulator as shown in the below image.
Output screen on Android Emulator


Tuesday, December 13, 2011

Android Development Environment Setup


This post is for new Android Developers or for those who have little interest in android development and wanna see the android li’l closely J

Here are the crisp steps to setup the android development environment!!

The developers are able to setup Android development environment by using Netbeans or Eclipse IDE and also by using command line tools (Apache Ant). But, Eclipse IDE is the Android development environment recommended by Google. The Android Development Tools (ADT) is a plugin for the Eclipse IDE designed to give a powerful, integrated environment to build Android applications.

Android ADT plugin extends the functionalities of Eclipse and set up the Android projects quickly and create application UI, add components based on the Android Framework API, debug application using DDMS tool and export the apk (Android Package) file to the emulator.

Android Development Environment Set up Using Eclipse

a)    Install JDK: Download and install JDK 5 or JDK 6 from http://java.sun.com/javase/downloads.

b)    Install Eclipse IDE: Download Eclipse Classic 3.5.1(or higher) https://www.eclipse.org/downloads/ and unzip it into the disk (in any folder).

c)    Download ADT Plugin: Download the latest version of Android ADT plugin for Eclipse http://developer.android.com/sdk/eclipse-adt.html and save it as a zip file into the disk (in any folder).

d)    Download Android SDK starter package: Download the Android SDK pack .zip archive according to the operating system of development computer (Windows/Linux i386/Mac OS X) http://developer.android.com/sdk/index.html and unpack it into the disk (in any folder). By default, the SDK files are unpacked into a directory named android-sdk-<machine-platform>.

e)    Configure ADT plugin with Eclipse:  Android offers a custom plugin for the Eclipse IDE, Android Development Tools (ADT).  Following the steps to configure it with the Eclipse.

·         Select Eclipse->Help->Install New Software, in the available dialog Select Add and enter the name of plugin (ex: “Android Plugin”) in the Name field and locate the ADT plugin zip file after selecting on Archive.

·         Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools and then click Next.

·         On the next dialog, click Next to read and accept the license agreement and install any dependencies, then click Finish.

·         Restart Eclipse.

f)    Configure Android SDK Starter Package: Select Eclipse->Window->Preferences, in the available dialog, select Android from the left panel and in the right panel of the dialog, click on Browse to locate the Android SDK root directory named as android-sdk-<machine-platform> and click on Apply and OK.

g)    Adding SDK Platforms for different Android OS versions and samples: Select Eclipse->Window->Android SDK and AVD Manager. Now in available dialog, select Available Packages and install the latest version of the SDK.

Exploring the SDK directory (optional): On exploring the SDK directory, the contents inside the root directory are add-on/, docs/, platform-tools/, platforms/, samples/, tools/, SDK Readme.txt, SDkManager.txt
Enjoy coding for android :)