Android

Installing APK Files on Android Device Emulator

Let me first clear one thing, You do not need Eclipse or Eclipse-plugin the Android Development Tools (ADT) in order to run .APK file (adhoc builds) on emulator. They required for the software/application development for Android, but are not necessary for application adhoc testing on emulator.

You will need to download the Android SDK, which can be obtained here: http://code.google.com/android/download.html

Before running .apk into emulator, it is needed to setup the sdk first.

Installing the SDK:

After downloading the SDK, unpack the .zip archive to a suitable location on your machine. For the rest of this document, we will refer to the directory where you installed the SDK as $SDK_ROOT.

Optionally, you can add $SDK_ROOT/tools to your path:

  • On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to your $SDK_ROOT/tools to it. If you don’t see a line setting the path, you can add one:
    export PATH=${PATH}:
  • On a Mac, look in your home directory for .bash_profile and proceed as for Linux. You can create the .bash_profile, if you haven’t already set one up on your machine.
  • On Windows, right click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path under System Variables, and add the full path to the tools/ directory under $SDK_ROOT to it.

*Note* – Updating the SDK for newer releases means you might also need to update the PATH settings.

If you have not created android virtual device (AVD)  yet, then in ../tools directory,

run command ./android

This will open up the window to let you add virtual device with specific sdk version 1.6 or 2.0

To check AVDs present you can run the command ./android list avd

Using emulator:

1. Go to $SDK_ROOT/tools directory and execute the file ‘emulator.exe’.

You might need to also include android virtual device (AVD) to command line execution for example,

./emulator -avd TestDevice

Please wait couple of minutes until it loads. You should see the home screen of the android emulator.

2. Save/copy the APK file directly in the $SDK_ROOT/tools directory.

3. Goto Shell/Terminal/CommandPrompt, adb install fileName.apk (You will need to shell/terminal/cmd sessions live)

or ./adb install fileName.apk

4. if there is ‘Path not found’ error then you need to add $SDK_ROOT/tools directory to your system PATH settings correctly.

5. After above command executions, you will be able to see installed apk into emulator.

Good luck!

Regards,

Shail

Android Project structure


android-logo

PROJECT STRUCTURE:

When new Android Application created. It use specific directory tree structure showing in eclipse SDK platform .There are Eight key items show in project tree structure as follows

1. AndroidManifest.Xml

2. bulid.xml

3. bin/

4. libs

5. src/

6. res/

7. assests

8. gen

project structure

AndroidManifest.xml :

When creating Android application must have an AndroidManifest.xml file in its root directory. It is an XML file describing the application being built and it contains activity, services, uses permission etc.

When creating a new project automatically generated file in project it contains only single main activity of project.

  • It describes the components of the application‚ the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities .These declarations let the Android system know what the components are and under what conditions they can be launched.
  • IN AndroidManifest.xml ¬†uses-permission elements, to indicate what permissions your application will need in order to function properly,

Example

android.permission.CALL_EMERGENCY_NUMBERS
android.permission.READ_CONTACT
android.permission.SET_WALLPAPER.

  • permission elements, to declare permissions that activities or services might require other applications hold in order to use your application’s data or logic ‚
  • instrumentation elements, to indicate code that should be invoked on key system events, such as starting up activities, for the purposes of logging or monitoring
  • uses-library elements, to hook in optional Android components, such as mapping services
  • its declares the minimum level of the Android API that used in applications as well as it declare verion name and version code just like

Example

android:versionCode=“1″

android:minSdkVersion=“3″

android:versionName=“1.0″

Build.Xml:

It is an ANT script for compiling the application and installing on the device.

BIN /:

When you compile your project (via ant or the IDE), the results go into the bin/ directory under your project root.

bin/classes/ holds the compiled Java classes

Bin/classes.dex holds the executable created from those compiled Java classes

bin/nameapp.ap_ holds your application’s resources, packaged as a ZIP file

bin/namedebug.apk or bin/nameapp-unsigned.apk is the actual Android application (where nameap is the name of your application)

The .apk file is a ZIP archive containing the .dex file, the compiled edition of your resources, any un-compiled resources (such as what you put in and the AndroidManifest.xml file. )

SRC/:

It contains all source code file (.java file) of android application. E.g hello_world.java

RES/:

Resources are to store all external contents that used in android applications.

These are external elements that you want to include and reference within your application, like images, audio, video, text strings, layouts, themes, etc.It contains all resources that are used in android application

Root directory:

  1. res/drawable : its contain images ,pictures (png, jpeg etc) e.g. .icon.png
  2. res/layout : contains XML(User Interface) that UI layout used in Project or view window of an application.(E.g. main.xml)
  3. res/Values : it declare Arrays, colors, dimensions, strings, and styles.(E.g. strings.xml)
  4. res/raw : it contains non-complied file (e.g. Audio file .mp3, video file .mpg)

E.g. it create an xml file  in values directory

<?xml version=“1.0″ encoding=“utf-8″?>

<resources>

<string name=“hello”>Welcome to Mobisoft Infotech! </string>

<string name=“app_name”>Hello world</string>

</resources>

ASSETS:

Assets it also store an external content refer in android applications. Just like images, audio, video, text strings .It same as resources but different in assets directory will maintain its raw file format and, in order to read it, you must use the AssetManager to read the file as a stream of bytes. So keeping files and data in resources (res/) makes them easily accessible.

libs/:

It’s holds any third-party Java JARs your application Requires.

GEN:

In Eclipse create an application that time auto generated R.java file in gen directory. The R.java file is an index (id) into all the resources defined in the file. This class files use in source code file or it gives for reference or location user interface object that uses in sources code.

Imp Note: Don’t change any code or id (assign value).

Android 2.0.1, Release

eclair-android (1)

In journey of android OS from November 2005 as little known company in mobile OS to December 2009 with 27% Market Share. It going better and better with their functionality and facilities.

devices with versions

See Video at Introduction to android 2.0

Android 2.0 looks to be a major improvement in Google’s mobile OS and we couldn’t be more excited about it. From native Exchange support to native Facebook support (it will sync with your contacts), browser improvements, a completely updated Maps application, unified email and UI makeover

New User Features

Contacts and accounts Contacts

Contacts seem to be much some great functionality built right in. Instead of hitting the contact and then diving through it to find the contact information you need, just tap the contact’s photo. Up will spring a clean and tidy sub-menu with the pertinent information which can be clicked on. Send someone an email instantly, open up their Facebook profile, or even call them.

Multiple accounts can be added to a device for email and contact synchronization, including Exchange accounts. (Handset manufacturers can choose whether to include Exchange support in their devices.)

  • Developers can create sync adapters that provide synchronization with additional data sources.
  • Quick Contact for Android provides instant access to a contact’s information and communication modes. For example, a user can tap a contact photo and select to call, SMS, or email the person. Other applications such as Email, Messaging, and Calendar can also reveal the Quick Contact widget when you touch a contact photo or status icon.

Email Email

Microsoft Exchange compatibility looks to be built-in to the OS now, and the new unified Inbox is perfect for keeping up with your personal and corporate email. You can star (flag for the corporate world) emails, mark multiple as read or unread, delete, forward ‚ whatever you want basically. Emails load effortlessly. Unfortunately (or not so unfortunately) the unified Inbox won‚Äôt work with your Gmail account as that uses the specific Google-made Gmail email application in Android.

  • Exchange support.
  • Combined inbox to browse email from multiple accounts in one page.

Messaging massaging

  • Search functionality for all saved SMS and MMS messages.
  • Auto delete the oldest messages in a conversation when a defined limit is reached.

Camera Camera

  • Built-in flash support
  • Digital zoom
  • Scene mode
  • White balance
  • Color effect
  • Macro focus

Android virtual keyboard

  • An improved keyboard layout to makes it easier to hit the correct characters and improve typing speed.
  • The framework’s multi-touch support ensures that key presses aren’t missed while typing rapidly with two fingers.
  • A smarter dictionary learns from word usage and automatically includes contact names as suggestions.

Browser Browser

The browser has a nice little UI makeover with a redone URL entry bar which includes a Favicon. In terms of performance, no this version we have doesn’t have Flash 10, Google keeps making strides in the browser space. It’s worlds better than anything we’ve used previously on a stock Android OS, and jumps one notch higher than HTC’s customized browser. There is not multi-touch in here as of now, but, you can double tap to zoom in and zoom out

Refreshed UI with actionable browser URL bar enables users to directly tap the address bar for instant searches and navigation.

  • Bookmarks with web page thumbnails.
  • Support for double-tap zoom.
  • Support for HTML5:
  • Database API support, for client-side databases using SQL.
  • Application cache support, for offline applications.
  • Geolocation API support, to provide location information about the device.
  • <video> tag support in fullscreen mode.

Calendar Cal

  • Agenda view provides infinite scrolling.
  • Events indicate the attending status for each invitee.
  • Invite new guests to events.

Maps Maps

Maps have been updated to include Layers. We’d imagine this will grow over time but now you can overlay search queries, Wikipedia entries, Latitude buddies, traffic, transit lines, and even load remote My Maps where you can share and receive directions with others. Android 2.0 seems to have some multi-touch gestures built-in like two-finger tapping in Maps, that will zoom in, however, there’s no gesture to zoom out and pinching doesn’t work.

There’s also a new option for Text-to-speech and generally with Android 2.0, you’re given more control over the settings of your phone and more opportunities to customize it based on your liking. Things like doing a voice search across the internet, getting driving directions, viewing a location on a map, selecting a contact, searching through your phone, etc. It’s very cool that you can say, ‘map of gas stations’ and that will open Google Maps and show you on the map where all the gas stations are closest to you.

The Building Blocks of Android Application

Android-Building-Blocks

Activities

The easiest way to think of an Android Activity is to relate a visible screen to an Activity The building block of the user interface is the activity. You can think of an activity as the window or dialog in a desktop application. While it is possible for activities to not have a user interface. There will one activity(.java file) extends the class Activity for one Screen(.xml file). An Android application will often contain more than one Activity that menace more than one screen. Each Activity displays a user interface and responds to system and user initiated events.

Intents

Intents used to assist in navigation from one activity to the next Intents are system messages, running around the inside of the device, notifying applications of various events, from hardware state changes (e.g.,an SD card was inserted), to incoming data (e.g., an SMS message arrived). You create your own intent object, to launch other activities.

Services

Service, which runs in the background and does not generally present a direct User Interface. Services, on the other hand, are designed to keep running, independent of any activity. You might use a service (extends Service class) for checking for updates to time, or to play back music.

BroadcastReceiver

If an application desires to receive and respond to a global event, such as the phone ringing or an incoming text message, it must register itself as an BroadcastReceiver. An application registers to receive Intents in a couple of different manners:

The application implements a <receiver> element in the AndroidManfest.xml file which describes the BroadcastReceiver’s class name and enumerates its IntentFilters. Remember, the IntentFilter is a descriptor of the Intent an application desires to process. If the receiver is registered in the AndroidManifest.xml file, it does not have to be running in order to be triggered when the event occurs as the application is started automatically upon the triggering event. All of this house-keeping is managed by Android. AndAn application registers itself at runtime via the Context class’s RegisterReceiver method also.

Content Providers

Content providers provide a level of abstraction for any data stored on the device that is accessible by multiple applications. The Android development model encourages you to make your own data available to other applications, as well as your own ‚ building a content provider lets you do that, while maintaining complete control over how your data gets accessed.

Android is Open Source

Google is hardly the first company to try using open-source software to shake up the industry. Open Handset Alliance, and the open-source community made all of the work that they have poured into the mobile platform is now officially available, for free, as the Android Open Source Project.

What is open

The core Android platform will be 100% open source. Even multimedia codecs, which historically are held close to the vest will be open. Except where noted, everything will use the Apache software license (ASL v2). This is the same open source license used by projects like the Apache HTTP server, Tomcat, Harmony, and many other large projects in the open source community.

There are two exceptions to the Apache license rule:

Software that is already covered by by a free/open source license will continue to use that license. Most notably, this includes Google’s enhancements to the Linux kernel. Linux uses the GNU Public License (GPL v2) so enhancements to the kernel will use the same license.

Any software that touches Eclipse, for example the Eclipse Android Development Tools plug-in (ADT) will be licensed under the Eclipse Public License (EPL), because that’s what Eclipse uses.

Google plans to make a few of their applications closed-source, including their GMail application. These programs are not part of the core Android system, even though they may be bundled with Android phones.

Openness

Android was built from the ground-up to enable developers to create compelling mobile applications that take full advantage of all a handset has to offer. It is built to be truly open. For example, an application could call upon any of the phone’s core functionality such as making calls, sending text messages, or using the camera, allowing developers to create richer and more cohesive experiences for users. This is true, as a developer you can do everything, from sending short messages with just 2 lines of code, up to replacing even the HOME-Screen of your device. One could easily create a fully customized operating system within weeks, providing no more of Google’s default application to the user. Android is built on the open Linux Kernel. Furthermore, it utilizes a custom virtual machine that has been designed to optimize memory and hardware resources in a mobile environment. Android will be open source; it can be liberally extended to incorporate new cutting edge technologies as they emerge. The platform will continue to evolve as the developer community works together to build innovative mobile applications.3

Different Layers of Android

android-architecture-485b

The Red Layer

Android_red_Layer

The red layer from represents the services offered by the Linux kernel and associated GNU utility packages ported to the ARM architecture. These components are licensed under the GNU [General Public License], the GPL, or the GNU Lesser General Public License, the LGPL. Being subject to the GNU GPL and LGPL licenses, these components are licensed with all source code included. Furthermore, due to the viral nature of the GPL license, any modification to this layer or derived work must be distributed as source to any 3rd parties using the same licensing terms. The GNU/Linux ARM port is mature, stable, and used in many embedded projects both in and outside of Google.

The Green Layer

android_green_layer

The green layer consists entirely of open source libraries available under various licenses. Some of the libraries come from the GNU project itself. The licenses here vary from the LGPL, BSD, MIT and are completely in the public domain in the case of the SQLite database. However, even if the licenses of some of the components found in this layer are more permissive and could allow a hardware vendor for customizations not found in other Android handsets, Google has created the Open Handset Alliance that owns the Android trademark. As part of this effort, any phone that wishes to be branded as an Android handset must meet the non-fragmentation rule. As such, any phone that would customize the libraries found in this layer, add libraries or remove them altogether would no longer be able to brand itself as an Android phone. Furthermore, under this same pledge, its license to the proprietary Dalvikvirtual machine found at the core of the Android platform would be considered null and void.

The Blue Layer (Application Frameworks)

Android_blue_Layer

In this layer, the application developer has access to what Android refers to as ‚ ‘service’ processes. These services are invisible to the user of the handset. Application developers can communicate with these services via a message bus. For example, a contact application might instigate a phone call at the behest of a user request by calling on the services of the telephony manager. All code found in this section is currently closed source, is written in Java specifically for the Dalvik virtual machine. It is not yet clear under what license these modules will be made available in the future.

Android

Android Logo

What is android ?

Android is a mobile operating system running on the Linux kernel. It was initially developed by Android Inc., a firm later purchased byGoogle, and lately by the “Open Handset Alliance“. It allows developers to write managed code in the Java language, controlling the device via Google-developed Java libraries.

Who is behind Android?

Google, which is a leading player in the initiative. The Open Handset Alliance is an organization of approximately 47 organizations committed to bringing a better‚ and open‚ mobile phone to market. This group includes members like Sprint, T-Mobile, Intel, Broadcom, Motorola, Samsung, Google, eBay, amongst others. A quote taken from their website says it best, Android was built from the ground up with the explicit goal to be the first open, complete, and free platform created specifically for mobile devices.

The Open Handset Alliance released the Google Android SDK on November 12th, 2007. The impact was unbelievable, almost every IT/programming-related news-page dumped a news-post about the SDK release – the Google Groups  was overwhelmed with over 2000 Messages within the first two Days. The idea of the Android Platform was and still is amazing and is of course attracting more and more programmers every day. Especially the open architecture based on Intents and the possibility to replace even the Home-application grant a really large amount of flexibility to the whole platform.

The weeks and months before Google released the Android SDK there had been a lot of rumors about a so called GPhone. It was said to be a mobile device manufactured by Google providing free communication by showing context-sensitive advertisements to the user on the device itself.

android phone

But on November 5th 2007 Andy Rubin (Google Director of Mobile Platforms) announced: ‘Android’ is more significant and ambitious than a single phone. Google within the Open Handset Alliance (OHA) delivers a complete set of software for mobile devices: an operating system, middleware and key mobile applications. Major news sites grabbed the discomforts of some developers who said that Android is full of bugs and heavily lacks of documentation. But the majority says that Android is not buggier than any other software at this stage.