Anroid os and to create android app

Embed Size (px)

Citation preview

  • 7/29/2019 Anroid os and to create android app

    1/66

    Android

  • 7/29/2019 Anroid os and to create android app

    2/66

    Topics Smart phones

    What Is Android?

    Downloading and Installing Eclipse

    Downloading and Installing the Android SDK

    Exploring the Android SDK

    Application: Hello World! View Layouts

    Android Widgets

    Using Intents and the Phone Dialer

  • 7/29/2019 Anroid os and to create android app

    3/66

    Smart Phones

    Smartphones combine the mobile phone with another streamof technology - the computer, which adds the smart insmartphone.

    MainFrame -> PC -> Laptops -> PDA -> Smartphone

    Like PDAs, smartphones can run applications such asorganizers, games,and communications programs (e.g.email, browser).

    The smartphones goal, however, is not just to limit thenumber of devices you carry, but also to combine mobilephone and computing technologies in a synergistic way.

  • 7/29/2019 Anroid os and to create android app

    4/66

    Mobile OS Structure

    A mobile OS is a software platform on top of which otherprograms called application programs, can run onmobile devices such as PDA, cellular phones,smartphone and etc.

    Low-Level Hardware, Manufacturer Device Drivers

    Device Operating System Base, Kernel

    OS Libraries

    Applications

  • 7/29/2019 Anroid os and to create android app

    5/66

    Mobile OS Platforms

    There are many mobile operating systems. Thefollowings demonstrate the most important ones: Java ME Platform Palm OS

    Symbian OS Linux OS Windows Mobile OS BlackBerry OS

    iPhone OS Google Android Platform

  • 7/29/2019 Anroid os and to create android app

    6/66

    Symbian OS Structure

    Hardware

    Symbian OS Base- Kernel

    Symbian OSLibraries

    Servers

    Application Engines

    KVM

  • 7/29/2019 Anroid os and to create android app

    7/66

    Windows Mobile OS

    Windows Mobile is a compact operating system designedfor mobile devices and based on Microsoft Win32.

    It is run on Pocket PCs, Smartphones and Portable media

    centers.

    It provides ultimate interoperability. Users with variousrequirements are able to manipulate their data.

  • 7/29/2019 Anroid os and to create android app

    8/66

    iPhone OS

    iPhone OS is an operating system run on iPhone and iPod.

    It is based on Mach Kernel and Drawin core as Mac OS X.

    The Mac OS X kernel includes the following component:

    Mach Kernel BSD I/O component File Systems

    Networking components

  • 7/29/2019 Anroid os and to create android app

    9/66

    Topics Smart phones

    What Is Android?

    Downloading and Installing Eclipse

    Downloading and Installing the Android SDK

    Exploring the Android SDK

    Application: Hello World! View Layouts

    Android Widgets

    Using Intents and the Phone Dialer

  • 7/29/2019 Anroid os and to create android app

    10/66

    Background

    Software platform from Google and the Open Handset

    Alliance July 2005, Google acquired Android, Inc. November 2007, Open Handset Alliance formed to develop

    open standards for mobile devices

    October 2008, Android available as open source December 2008, 14 new members joined Android project

    April 30, 2009: Official 1.5 Cupcake release

    September 15, 2009: 1.6 SDK Donut release

    October 26, 2009: 2.0 SDK clair release

    Updates to the clair release:

    2.0.1 on December 3, 2009

    2.1 on January 12, 2010

  • 7/29/2019 Anroid os and to create android app

    11/66

    Features

    Reuse and replacement of components. Dalvik virtual machine. Integrated browser. Optimized graphics. SQLite. Media support. GSM Telephony. Bluetooth, EDGE, 3G, and WiFi.

    Camera, GPS, compass, and accelerometer. Rich development environment.

  • 7/29/2019 Anroid os and to create android app

    12/66

    Application Fundamentals

    Apps are written in Java

    Bundled by Android Asset Packaging Tool

    Every App runs its own Linux process

    Each process has its own Java Virtual Machine Each App is assigned a unique Linux user ID

    Apps can share the same user ID to see each others files

  • 7/29/2019 Anroid os and to create android app

    13/66

    Android Architecture

  • 7/29/2019 Anroid os and to create android app

    14/66

    Android Architecture Linux Kernel: Android relies on Linux for core system services

    such as security, memory management, process management.

    Android Runtime: it provides a set of core libraries whichsupports most of the functionality in the core libraries of Java.The Android Virtual Machine known as Dalvik VM relies on thelinux kernel for some underlying functionality such as

    threading,

    Libraries: Android includes a set of C/C++ libraries. Theselibraries are exposed to developers through the Androidapplication framework. They include media libraries, system Clibraries, surface manager, 3D libraries, SQLite and etc.

    Application Framework: it provides an access layer to theframework APIs used by the core applications. It allows

    components to be used by the developers.

  • 7/29/2019 Anroid os and to create android app

    15/66

    Challenges

    CPU typically runs 500-600 Mhz

    RAM available to an App may only be a few megabytes

    Disk (flash) access is very slow

    Lifecycle - apps must pause/quit often, and restore to give the

    illusion that they are always running

    Typical screen may be HVGA (320x480) may be in portrait orlandscape

    Very high DPI - small text may not be readable

    Touch resolution is very low (~25 pixel)

    Network access may be slow and (very) intermittent

  • 7/29/2019 Anroid os and to create android app

    16/66

    Topics Smart phones

    What Is Android?

    Downloading and Installing Eclipse

    Downloading and Installing the Android SDK

    Exploring the Android SDK

    Application: Hello World! View Layouts

    Android Widgets

    Using Intents and the Phone Dialer

  • 7/29/2019 Anroid os and to create android app

    17/66

    Downloading and Installing EclipseBefore downloading and installing Eclipse, make sure JavaRuntime Environment (JRE) is downloaded and installed onthe machine.

    Eclipse requires JRE to run Download JDK (includesJRE) from www.oracle.com/technetwork/java/javase/downloads/index.html

    Download Eclipse from www.eclipse.org/downloads/

    Unzip the package to a folder. The editors executable is

    eclipse.exe.( There is no installation wizard)

    Create a shortcut for the eclipse.exe and copy it to thedesktop

    http://www.eclipse.org/downloads/http://www.eclipse.org/downloads/
  • 7/29/2019 Anroid os and to create android app

    18/66

    Topics Smart phones

    What Is Android?

    Downloading and Installing Eclipse

    Downloading and Installing the Android SDK

    Exploring the Android SDK

    Application: Hello World! View Layouts

    Android Widgets

    Using Intents and the Phone Dialer

  • 7/29/2019 Anroid os and to create android app

    19/66

    Downloading SDK

    Download the Android SDK fromhttp://developer.android.com/sdk/index.html

    Extract it and note down the location.

    Add the SDKpath to the Environment variable.

  • 7/29/2019 Anroid os and to create android app

    20/66

    Installing ADT Plug in for Eclipse1. Start Eclipse, then select Help > Install New Software....

    2. Click Add, in the top-right corner.

    3. In the Add Repository dialog that appears, enter "ADT Plugin" fortheName and the following URL for the Location:https://dl-ssl.google.com/android/eclipse/.

    4. Click OK.

    5. In the Available Software dialog, select the checkbox next toDeveloper Tools and click Next.

    6. In the next window, you'll see a list of the tools to be downloaded.Click Next.

    7. Read and accept the license agreements, then click Finish.

    8. When the installation completes, restart Eclipse.

  • 7/29/2019 Anroid os and to create android app

    21/66

    Configuring the ADT Plugin

    1. Select Window > Preferences... to open the Preferences panel.

    2. Select Android from the left panel.

    3. For the SDK Location in the main panel, click Browse... and locateyour downloaded SDK directory.

    4. Click Apply, then OK.

  • 7/29/2019 Anroid os and to create android app

    22/66

    Adding Components

    1. From within Eclipse, select Window > Android SDK and AVDManager.

    2.

  • 7/29/2019 Anroid os and to create android app

    23/66

    Smart phonesWhat Is Android?

    Downloading and Installing EclipseDownloading and Installing the Android SDKExploring the Android SDKApplication: Hello World!

    View LayoutsAndroid WidgetsUsing Intents and the Phone Dialer

  • 7/29/2019 Anroid os and to create android app

    24/66

    What is in the Android SDK

    The Android SDK consists of

    1. Docs, Contains all of the accompanying Android documentation.

    2. Samples Contains six sample applications that you can compile and test fromwithin Eclipse.

    3. Tools Contains all of the development, compilation, and debugging tools.

  • 7/29/2019 Anroid os and to create android app

    25/66

    Tools in the Android SDK

    The Android Emulator is used to run your applicationsin a pseudo-Android environment.

    Android Debug Bridge or adb (adb.exe) allows you toissue commands to the Emulator.exe tool.

    MKSDCARD.exe is a tool if you are testing anapplication that will need to read / write files on SDMemory Card.

    DX.exe is the compiler of the Android SDK. When runagainst Java files, will create files with .dex extensions-Dalvik executable format.

  • 7/29/2019 Anroid os and to create android app

    26/66

    Smart phonesWhat Is Android?

    Downloading and Installing EclipseDownloading and Installing the Android SDKExploring the Android SDKApplication: Hello World!

    View LayoutsAndroid WidgetsUsing Intents and the Phone Dialer

    C ti A d id P j t

  • 7/29/2019 Anroid os and to create android app

    27/66

    Creating an Android Project

    C ti A d id P j t

  • 7/29/2019 Anroid os and to create android app

    28/66

    Creating an Android Project

    Name of the project file

    Name of the Application

    Name of the Package

    Name of the Activity

    E i i th A d id C t d Fil

  • 7/29/2019 Anroid os and to create android app

    29/66

    Examining the Android-Created FilesRoot Directory : It is the home, or

    repository, for all of project files.

    Manifest: XML file where global settings are

    made.

    Library: A list of the Referenced Libraries.

    android.jar, the Android SDK

    Res: project resources are held.

    Drawable-***: contains actual image files

    that your application can use and

    reference.

    Layout: Holds main.xml, that is referenced

    by the application when building its

    interface..

    Assets: to hold raw asset files, audio files

    for streaming and animation assets

    Src: contains all the source files for yourproject

    H ll ld XML B d

  • 7/29/2019 Anroid os and to create android app

    30/66

    Hello world XML Based

    package android_programmers_guide.HelloWorldText;

    import android.app.Activity;

    import android.os.Bundle;

    public class HelloWorldText extends Activity

    {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle icicle)

    {

    super.onCreate(icicle);

    setContentView(R.layout.main);

    }

    }

    H ll ld XML B d

  • 7/29/2019 Anroid os and to create android app

    31/66

    Hello world XML Based

    H ll ld C d B d

  • 7/29/2019 Anroid os and to create android app

    32/66

    Hello world Code Based

    H ll ld C d B d

  • 7/29/2019 Anroid os and to create android app

    33/66

    Hello world Code Based

    package android_programmers_guide.HelloWorldText;

    import android.app.Activity;import android.os.Bundle;

    import android.widget.TextView;

    public class HelloWorldText extends Activity

    {/** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle icicle)

    {

    TextView HelloWorldTextView = new TextView(this);

    HelloWorldTextView.setText("Hello World!");

    setContentView(HelloWorldTextView);

    }

    }

    H ll ld U i I

  • 7/29/2019 Anroid os and to create android app

    34/66

    Hello world Using an Image

    Example application that shows Hello world with an Image by

    XML Layout based UI.

    Code based UI.

    T i

  • 7/29/2019 Anroid os and to create android app

    35/66

    Topics What Is Android?

    Downloading and Installing Eclipse

    Downloading and Installing the Android SDK

    Exploring the Android SDK

    Application: Hello World!

    View Layouts Android Widgets

    Using Intents and the Phone Dialer

    Layouts

  • 7/29/2019 Anroid os and to create android app

    36/66

    Layouts

    Controls how Views are laid out

    LinearLayout : single row or column

    RelativeLayout : relative to other Views

    TableLayout : rows and columns AbsoluteLayout : < x, y > coordinates

    Linear Layout

  • 7/29/2019 Anroid os and to create android app

    37/66

    Linear Layout

    All elements are arranged in a descending column fromtop to bottom or left to right.

    Each element can have gravity and weight propertiesthat denote how they dynamically grow and shrink to fill

    space. Elements arrange themselves in a row or columnnotation based on the android:orientation parameter.

    Linear Layout Example

  • 7/29/2019 Anroid os and to create android app

    38/66

    Linear Layout - Example

    All elements are arranged in a descending column fromtop to bottom or left to right.

    Each element can have gravity and weight propertiesthat denote how they dynamically grow and shrink to fill

    space. Elements arrange themselves in a row or columnnotation based on the android:orientation parameter.

    Linear Layout

  • 7/29/2019 Anroid os and to create android app

    39/66

    Linear Layout

    Relative Layout

  • 7/29/2019 Anroid os and to create android app

    40/66

    Relative Layout

    Each child element is laid out in relation to other childelements.

    Relationships can be established so that children will

    start themselves where a previous child ends. Children can relate only to elements that are

    listed before them.

    Note that IDs are required so that widgets can reference

    each other.

    Relative Layout Example

  • 7/29/2019 Anroid os and to create android app

    41/66

    Relative Layout - Example

    Absolute Layout

  • 7/29/2019 Anroid os and to create android app

    42/66

    Absolute Layout

    Each child must be given a specific location within thebounds of the parent layout object.

    The Absolute Layout object is probably the easiest tobuild and visualize but the hardest to migrate to a new device

    or screen size.

    Absolute Layout Example

  • 7/29/2019 Anroid os and to create android app

    43/66

    Absolute Layout - Example

  • 7/29/2019 Anroid os and to create android app

    44/66

    Table Layout

    Table Layout is a layout object that allows you to specifytable rows.

    Android tries to arrange each of the child elements intothe correct row and columns.

    Table Layout - Example

  • 7/29/2019 Anroid os and to create android app

    45/66

    Table Layout - Example

    Topics

  • 7/29/2019 Anroid os and to create android app

    46/66

    Topics What Is Android?

    Downloading and Installing Eclipse

    Downloading and Installing the Android SDK Exploring the Android SDK

    Application: Hello World!

    View Layouts Android Widgets

    Using Intents and the Phone Dialer

    Labels

  • 7/29/2019 Anroid os and to create android app

    47/66

    Labels

    The simplest widget is the label, referred to in Android as aTextView.

    Bits of text not editable directly by users, used to identifyadjacent widgets (e.g., a "Name:" label before a fieldwhere one fills in a name).

    Button

  • 7/29/2019 Anroid os and to create android app

    48/66

    Button

    import android.view.View;import android.widget.Button;

    public class Helloworld extends Activityimplements View.OnClickListener

    {Button btn;

    btn = (Button)findViewById(R.id.ok);btn.setOnClickListener(this);

    }

    public void onClick(View view){

    btn.setText("New Text");

    }

    Check Box

  • 7/29/2019 Anroid os and to create android app

    49/66

    Check Box

    import android.widget.CheckBox;

    public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);setContentView(R.layout.main );

    CheckBox checkbox;checkbox =

    (CheckBox)findViewById(R.id.testCheckBox);checkbox.setOnClickListener(this);

    }

    public void onClick(View v){

    }

    Edit Text

  • 7/29/2019 Anroid os and to create android app

    50/66

    Edit Text

    import android.widget.EditText;

    public void onCreate(Bundle savedInstanceState)

    {super.onCreate(savedInstanceState);setContentView(R.layout.main );

    }

    Radio Button

  • 7/29/2019 Anroid os and to create android app

    51/66

    Radio Button

    Topics

  • 7/29/2019 Anroid os and to create android app

    52/66

    Topics

    Smart phones

    What Is Android? Downloading and Installing Eclipse

    Downloading and Installing the Android SDK

    Exploring the Android SDK Application: Hello World!

    View Layouts

    Android Widgets

    Using Intents and the Phone Dialer

    What are Intents?

  • 7/29/2019 Anroid os and to create android app

    53/66

    What are Intents?

    An Intent is Androids method for relaying certain

    information from one Activity to another.

    You can think of an Intent as a message passed betweenActivities.

    Intents are broken up into two main categories:Activity Action Intents : Intents used to call Activities

    outside of your application. Only one Activity can handlethe Intent.

    Broadcast Intents : Intents that are sent out for multipleActivities to handle. An example of a Broadcast Intentwould be a message sent out by Android about thecurrent battery level. Any Activity can process this Intent

    and react accordingly.

    Broadcast Intents

  • 7/29/2019 Anroid os and to create android app

    54/66

    Broadcast Intents

    Broadcast Intent Message

    CALL_FORWARDING_STATE_CHANGED_ACTION The phones call forwarding state has changed

    CAMERA_BUTTON_ACTION The camera button has been pressed

    DATA_ACTIVITY_STATE_CHANGED_ACTION The devices data activity state has changed

    DATA_CONNECTION_STATE_CHANGED_ACTION There has been a change in the data connection state

    DATE_CHANGED_ACTION The phones system date has changed

    FOTA_CANCEL_ACTION Cancel pending system update downloads

    FOTA_INSTALL_ACTION An update has been downloaded and must be installedimmediately (sent by the system)

    MEDIA_BAD_REMOVAL_ACTION Sent when an SD Memory Card was removed butunsuccessfully unmounted from the system

    MESSAGE_WAITING_STATE_CHANGED The message waiting state on the phone has changed

    PACKAGE_ADDED_ACTION Sent when a new package has been installed on the device

    SCREEN_OFF_ACTION The screen has been shut off (sent by the device)

    SIGNAL_STRENGTH_CHANGED_ACTION The signal strength has changed

    SIM_STATE_CHANGED_ACTION The state of the SIM card has changed

    TIME_TICK_ACTION The current time has changed

    WALLPAPER_CHANGED_ACTION The devices wallpaper has been changed

    Activity Intents

  • 7/29/2019 Anroid os and to create android app

    55/66

    Activity Intents

    Activity Intent Message

    ADD_SHORTCUT_ACTION Add a function shortcut to the Android Home Screen

    ALL_APPS_ACTION List all the applications available on the device

    BUG_REPORT_ACTION Open the Bug Reporting Activity

    CALL_ACTION Answer an incoming call

    DELETE_ACTION Delete the specified data

    DIAL_ACTION Open the Dial Activity and dial the specified number

    EDIT_ACTION Provide editable access to the supplied data

    EMERGENCY_DIAL_ACTION Dial an emergency number

    FACTORY_TEST_ACTION Retrieve factory test settings

    GET_CONTENT_ACTION Select and return specified data

    INSERT_ACTION Insert an empty item

    MAIN_ACTION Establish the Activity start point

    PICK_ACTION Pick an item and return the selection

    PICK_ACTIVITY_ACTION Pick a given Activity (returns a class)

    RUN_ACTION Execute the given data

    Example - Using the Dialer

  • 7/29/2019 Anroid os and to create android app

    56/66

    Example Using the Dialer

    package android_programmers_guide.AndroidPhoneDialer;

    import android.app.Activity;import android.content.Intent;

    import android.os.Bundle;

    import android.net.Uri;

    public class AndroidPhoneDialer extends Activity

    {

    @Override

    public void onCreate(Bundle icicle)

    {

    super.onCreate(icicle);

    setContentView(R.layout.main);

    Intent DialIntent = new

    Intent(Intent.DIAL_ACTION,Uri.parse("tel:5551212"));

    /** Use NEW_TASK_LAUNCH to launch the Dialer Activity */

    DialIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );

    /** Finally start the Activity */

    startActivity(DialIntent);

    }

    }

    Example Calling a Number

  • 7/29/2019 Anroid os and to create android app

    57/66

    Example Calling a Number

    import android.content.Intent;

    import android.os.Bundle;

    import android.net.Uri;

    public class AndroidPhoneDialer extends Activity

    {

    public void onCreate(Bundle icicle)

    {

    super.onCreate(icicle);

    setContentView(R.layout.main);

    Intent CallIntent = new Intent(Intent.CALL_ACTION,Uri.parse("tel:5551212"));

    /** Use NEW_TASK_LAUNCH to launch the Call Activity */

    CallIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );

    /** Finally start the Activity */startActivity(CallIntent);

    }

    }

    Activity Permissions

  • 7/29/2019 Anroid os and to create android app

    58/66

    Activity Permissions

    Most Activity Action Intents fall into the category ofrequiring that the proper permission be set before Androidwill allow the action.

    Android just needs to make sure that only Activities withthe correct credentials be allowed to perform actions with

    Activities that are outside of their base.

    Permissions:

    ACCESS_ASSISTED_GPS INTERNAL_SYSTEM_WINDOW

    ACCESS_CELL_ID RAISED_THREAD_PRIORITY

    ACCESS_GPS READ_CONTACTS

    ACCESS_LOCATION READ_FRAME_BUFFER ACCESS_SURFACE_FLINGER RECEIVE_BOOT_COMPLETED

    ADD_SYSTEM_SERVICE RECEIVE_SMS

    BROADCAST_PACKAGE_REMOVED RECEIVE_WAP_PUSH

    BROADCAST_STICKY RUN_INSTRUMENTATION

    CALL_PHONE SET_ACTIVITY_WATCHER

    CHANGE_COMPONENT_ENABLED_STATE SIGNAL_PERSISTENT_PROCESSES

    SET_PREFERRED_APPLICATIONS DELETE_PACKAGES

    Application Lifecycle

  • 7/29/2019 Anroid os and to create android app

    59/66

    Application Lifecycle

    Android Applications have no control over their own lifecycle.

    Android aggressively manages its resource doing what

    ever it takes to ensure that the device remainsresponsive.

    This means that processes will be killed without warning

    if necessary to free resources for higher priorityapplications.

    Activity states

  • 7/29/2019 Anroid os and to create android app

    60/66

    The state of each Activity is determined by its position on theActivity stack, a last-infirst-out collection of all the currentlyrunning Activities.

    When a new Activity starts, the current foreground screen ismoved to the top of the stack.

    If the user navigates back using theBack button, or the foreground

    Activity is closed, the next Activity

    on the stack moves upand becomes active.

    Activity states

    Activity states

  • 7/29/2019 Anroid os and to create android app

    61/66

    State transitions are nondeterministic and are handledentirely by the Android memory manager.

    Android will start by closing applications that contain inactiveActivities, followed by those that are stopped, and in extremecases, it will remove those that are paused.

    For seamless user experience, transitions between thesestates should be invisible to the user. It is important to saveall UI state changes and persist all data when an Activity is

    paused or stopped. Once an Activity does become active, itshould restore those saved values.

    Active Paused Stopped Inactive

    Activity states

    State Changes

  • 7/29/2019 Anroid os and to create android app

    62/66

    State Changes

    What makes an Android Application

  • 7/29/2019 Anroid os and to create android app

    63/66

    pp

    Android Application consists of loosely coupled componentsbound using a project Manifest.

    Building blocks of Android Application are:

    1. Activities

    2. Services3. Content Providers

    4. Intents

    5. Broadcast Receivers

    6. Notifications

    What makes an Android Application

  • 7/29/2019 Anroid os and to create android app

    64/66

    pp

    Activities:

    Applications presentation layer.

    Every screen in the application will be an extension oftheActivityclass.

    Activities use views to form GUI.

    Activities are equivalent to Forms in Desktop world.

    Services:

    These components run invisibly.

    They are used to perform regular processing that needsto continue even when the applicationActivitiesarentvisible.

    What makes an Android Application

  • 7/29/2019 Anroid os and to create android app

    65/66

    pp

    Content Providers:

    A sharable database.

    Preferred way of sharing data across processboundaries.

    It is possible to configure a content provider to permitaccess from other applications.

    Use Content providers exposed by other applications toaccess their stored data.

    Intents:

    Message passing Framework. Broadcast message system wide or to a target activity or

    service.

    What makes an Android Application

  • 7/29/2019 Anroid os and to create android app

    66/66

    pp

    Broadcast consumers:

    Intent Broadcast consumers

    By creating and registering a Broadcast receiver, anapplication can listen for broadcast intents.

    Notifications: Notifies user without stealing focus or interrupting their

    current activists.