Mobile application development lab

Embed Size (px)

Citation preview

  • 8/13/2019 Mobile application development lab

    1/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 1

    INTRODUCTION

    J2ME (Java 2 Micro Edition) is an advanced technology in Java, developed with the help

    of Java Community Process Program. J2ME is a reduced version of the Java API and

    Java Virtual Machine that is designed to operate within the limited resources available in theEmbedded computers and microcomputers. J2ME is targeted to developers of intelligent wireless

    devices and small computing devices who need to incorporate cross-platform functionality in their

    products. A key benefit of using J2ME is compatibility with all Java-enabled devices. Motorola,

    Nokia, Panasonic all have Java-enabled devices. A J2ME application is a balance between local

    and server-side processing. The Java Community Process Program used a two approaches to

    addressing the needs of small computing devices.

    Configurations: It is the Java run-time environment and core classes that operate on each device.

    A configuration defines the Java Virtual Machine for a particular small computing device. There

    are two configurations.

    J2ME ARCHITECTURE:

    There are 5 layers in J2ME Architecture.

    1. MIDP (Top Most Layer): Which contains Java APIs for user network connections,persistence storage, and the user interface? It also has access to CLDC libraries and MIDP

    libraries.

    2. J2ME APIs(Profiles): Which consists of the minimum set of application programminginterfaces for the small computing device

    3. Configurations: Which handles interactions between the profile and the JVM?4. JVM5. Operating System (Bottom Layer).

    MIDLETS:

    A MIDlet is a J2ME application which operates on an MIDP. A MIDlet is defined with at least a

    single class that is derived from the javax.microedition.midlet.MIDlet abstract class.

    A MIDlet is an event-based application. All routines executed in the MIDlet are invoked in

    response to an event reported to the MIDlet by the application manager. The initial event that

    occurs is when the MIDlet is started and the application manager invokes the startApp() method.

    StartApp ():called by the application manager when the MIDlet is started and contains

    statements that are executed each time the application begins execution. Public and have no return

    value nor parameter list.

    PauseApp ():called before the application manager temporarily stops the MIDlet. The

    application manager restarts the MIDlet by recalling the startApp() method. Public and have no

    return value nor parameter list.

    DestroyApp ():called prior to the termination of the MIDlet by the application manager. Public

    method without a return value. It has a boolean parameter that is set to true if the termination of

    the MIDlet is unconditional, and false if the MIDlet can throw a MIDletStateChangeException.

  • 8/13/2019 Mobile application development lab

    2/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 2

    The Basic Midlet Shell.

    public class BasicMIDletShell extends MIDlet

    {

    public void startApp(){ }

    public void pauseApp(){ }

    public void destroyApp( boolean unconditional){ }

    }

    Limitations with J2ME:

    Some ofthe limitations of J2ME compared with Core JAVA Some J2SE applications require classes that are not available in J2ME. Java applications wont run in the J2ME environment without requiring modification to

    the code.

    Devices that use the CDC configuration use the full Java Virtual Machine implementation,while

    devices that use the CLDC configuration use the Kjava Virtual Machine implementation. MIDlets are controlled by application management software (AMS). So we cant invoke a

    MIDLET like a J2SE Application.

    Sun Java Wireless Toolkit:

    The Sun Java Wireless Toolkit (WTK; formerly known as Java 2 Platform, Micro Edition

    (JavaME) Wireless Toolkit) is a state-of-the-art toolbox for developing wireless applications that

    are based on JavaME's Connected Limited Device Configuration (CLDC) and Mobile

    Information Device Profile (MIDP), and designed to run on cell phones, mainstream personal

    digital assistants, and other small mobile devices. The toolkit includes the emulation

    environments, performance optimization and tuning features, documentation, and examples that

    developers need to bring efficient and successful wireless applications to market quickly. The

    J2ME Wireless Toolkit is a comprehensive set of tools for building MIDP applications. The

    toolkit can be used standalone, or incorporated into many popular integrated development

    environments (IDEs). The Sun J2ME Wireless Toolkit supports the development of Java

    applications that run on devices such as cellular phones, two-way pagers, and palmtops.

  • 8/13/2019 Mobile application development lab

    3/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 3

    Building an application with the Wireless Toolkit consists of five basic steps:

    Start the toolkit, which is easier said than done. Look for the program calledKToolbarifyou're lost, which you probably will be your first time.

    Create a new project using the Create Project button. You'll be prompted to provide thename of the project as well as the name of the main MIDlet class that should be run to start

    the application. The toolkit will create a project directory for you using the project name

    you provide.

    Verify that the project properties you are shown are correct. We'll go over these in aminute.

    Write your Java source in your favorite editor or IDE (or copy existing code) and save into Thesrc subdirectory under the main project folder. Build your application using the Build button and use the Run button to test it in the

    device emulator of your choice. You'll have to download a ROM image for the Palm

    device emulator, but the others are included in your MIDP and CDC implementations.

  • 8/13/2019 Mobile application development lab

    4/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 4

    WEEK-1

    Aim: Write a J2ME program to print the hello world?

    Description:

    J2ME programs done by using the code java.

    By using the software sun Microsoft toolkit programs can be run. In the program first open the software. Open the project. Hello world program code can be write in java. Build the project. Run the project. In the output the mobile or media control can be display the hello world program. Finally output can be displayed in the mobile.

  • 8/13/2019 Mobile application development lab

    5/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 5

    SOURCE CODE:

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.MIDlet;

    public class HelloWorld extends MIDlet implements CommandListener {

    public void startApp() {

    Display display = Display.getDisplay(this);

    Form mainForm = new Form("HelloWorld");

    mainForm.append("Welcome to the world of Mobile");

    Command exitCommand = new Command("Exit", Command.EXIT, 0);

    mainForm.addCommand(exitCommand);

    mainForm.setCommandListener(this);

    display.setCurrent(mainForm);

    }

    public void pauseApp () {}

    public void destroyApp(boolean unconditional) {}

    public void commandAction(Command c, Displayable s) {

    if (c.getCommandType() == Command.EXIT)

    notifyDestroyed();}

    }

  • 8/13/2019 Mobile application development lab

    6/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 6

    Output:

  • 8/13/2019 Mobile application development lab

    7/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 7

    WEEK-2

    Aim: Write a J2ME program which creates the following kind of menu.

    Cut Copy Paste Delete Select all Unselect all

    Description:J2ME programs done by using the code java.

    By using the software sun Microsoft toolkit programs can be run. In the program first open the software. Open the project. Hello world program code can be write in java. Build the project. Run the project. In the output the mobile or media control can be display the menu creation in the first

    mobile .

    In the second mobile the cut, copy, paste, select all, unselect all options can be displayedin second mobile.

    Finally output can be displayed in the mobile.

  • 8/13/2019 Mobile application development lab

    8/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 8

    SOURCE CODE:

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.*;

    public class MenuCreation extends MIDlet

    {

    public ChoiceGroup ch;

    public Display display;

    public Form form;

    public MenuCreation()

    {

    display=Display.getDisplay(this);

    ch=new ChoiceGroup("Edit",Choice.EXCLUSIVE);

    ch.append("cut",null);

    ch.append("copy",null);

    ch.append("paste",null);

    ch.append("selectall",null);

    ch.append("unselect all",null);

    form=new Form("MenuCreation");

    form.append(ch);

    }

    public void startApp()

    {

    display.setCurrent(form);

    }

    public void pauseApp(){}

    public void destroyApp(boolean unconditional)

    {}

    }

  • 8/13/2019 Mobile application development lab

    9/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 9

    Output:

  • 8/13/2019 Mobile application development lab

    10/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 10

    Week -3

    Aim: Create a J2ME menu which has the following options(Event Handling):

    Cutcan be on/off Copycan be on/off pastecan be on/off deletecan be on/off select allpull all 4 options on unselect all-put all

    Description:J2ME programs done by using the code java.

    By using the software sun Microsoft toolkit programs can be run. In the program first open the software. Open the project. Hello world program code can be write in java. Build the project.

    Run the project. In the output the mobile or media control can be display the menu event in the first mobile

    .

    In the second mobile the cut, copy, paste, select all, unselect all options can be displayedin second mobile.

    Finally output can be displayed in the mobile.

  • 8/13/2019 Mobile application development lab

    11/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 11

    SOURCE CODE:

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.*;

    public class MenuEvent extends MIDlet implements CommandListener, ItemStateListener

    {

    public ChoiceGroup ch;

    public ChoiceGroup ch1;

    public Form form;

    public Form form1;

    public Display display;

    public Command Exit;

    public Command View;

    public Command Back;

    public StringItem st;

    public Item item;

    public MenuEvent()

    {

    display=Display.getDisplay(this);

    ch=new ChoiceGroup("EDIT",Choice.MULTIPLE);

    ch.append("cut",null);

    ch.append("copy",null);

    ch.append("paste",null);

    ch.append("delete",null);

    form=new Form(" ");

    form1=new Form("selected options are ");ch.setSelectedIndex(0,true);

    form.append(ch);

    ch1=new ChoiceGroup(" ",Choice.EXCLUSIVE);

    ch1.append("selectall",null);

    ch1.append("unselectall",null);

    ch1.setSelectedIndex(1,true);

    form.append(ch1);View=new Command("View",Command.OK,1);

    Exit=new Command("Exit",Command.EXIT,1);

  • 8/13/2019 Mobile application development lab

    12/62

  • 8/13/2019 Mobile application development lab

    13/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 13

    form1.append(st);

    display.setCurrent(form1);

    }

    else if(command==Exit)

    {

    destroyApp(true);

    notifyDestroyed();

    }

    }

    else if(displayable==form1)

    {

    if(command==Back)

    {

    display.setCurrent(form);

    st.setText(" ");

    }

    }

    }

    public void itemStateChanged(Item item)

    {

    int i=0;

    int size=ch.size();

    while(i

  • 8/13/2019 Mobile application development lab

    14/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 14

    Output:

  • 8/13/2019 Mobile application development lab

    15/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 15

    Week-4

    Aim: Create a MIDP Application, which draws a Bar Graph to the display. Data Values can be

    give at int [] array. You can enter four data(integer)values to the input text field.

    Description:

    J2ME programs done by using the code java.

    By using the software sun Microsoft toolkit programs can be run. In the program first open the software. Open the project.

    Hello world program code can be write in java. Build the project. Run the project. In the output the mobile or media control can be displayed in the first mobile with bar

    graph 1.

    In the second mobile we will give the values like t1, t2, t3,t4. By these values we can identify the graph with increase and decreasing images. Finally output can be displayed in the mobile.

  • 8/13/2019 Mobile application development lab

    16/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 16

    SOURCE CODE:

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.*;

    public class BarGraph extends MIDlet implements CommandListener

    {

    public Form form;

    public Display display;

    public Command Exit;

    public Command Ok;

    public Command Back;

    public Displayable d;

    public TextField t1;

    public TextField t2;

    public TextField t3;

    public TextField t4;

    public BarGraph()

    {

    display=Display.getDisplay(this);

    form=new Form("");

    t1=new TextField("t1","",30,TextField.ANY);

    t2=new TextField("t2","",30,TextField.ANY);

    t3=new TextField("t3","",30,TextField.ANY);

    t4=new TextField("t4","",30,TextField.ANY);

    form.append(t1);

    form.append(t2);form.append(t3);

    form.append(t4);

    Ok=new Command("Ok",Command.OK,1);

    Exit=new Command("Exit",Command.EXIT,1);

    Back=new Command("BACK",Command.BACK,1);

    form.addCommand(Ok);

    form.addCommand(Exit);form.setCommandListener(this);

    }

  • 8/13/2019 Mobile application development lab

    17/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 17

    public void startApp()

    {

    display.setCurrent(form);

    }

    public void pauseApp()

    {

    }

    public void destroyApp(boolean unconditional)

    {

    }

    public void commandAction(Command command,Displayable displayable)

    {

    if(displayable==form)

    {

    if(command==Ok)

    {

    int[] data=new int[4];

    data[0]=Integer.parseInt(t1.getString());

    data[1]=Integer.parseInt(t2.getString());

    data[2]=Integer.parseInt(t3.getString());

    data[3]=Integer.parseInt(t4.getString());

    d=new BarCanvas(data);

    d.addCommand(Back);

    d.setCommandListener(this);

    display.setCurrent(d);}

    else if(command==Exit)

    notifyDestroyed();

    }

    else if(displayable==d)

    {

    if(command==Back)

    display.setCurrent(form);

    }

  • 8/13/2019 Mobile application development lab

    18/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 18

    }

    }

    class BarCanvas extends Canvas

    {

    int[] data;

    public int x;

    public int y;

    public int y1;

    public int h;

    public BarCanvas(int[] data)

    {

    this.data=data;

    x=10;

    }

    public void paint(Graphics g)

    {

    g.setColor(255,255,255);

    g.fillRect(0,0,this.getWidth(),this.getHeight());

    g.setColor(255,125,100);

    int i=0;

    y1=data[0];

    h=200;

    while(i

  • 8/13/2019 Mobile application development lab

    19/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 19

    Output:

  • 8/13/2019 Mobile application development lab

    20/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 20

    Week-5

    Aim: Create an MIDP application which examine that a phone number, which a user has

    entered is in the given format (Input checking):

    Area code should be one of the following:040,041,050,0400,044 There should 6-8 numbers in telephone number(+area code)

    Description:

    J2ME programs done by using the code java.

    By using the software sun Microsoft toolkit programs can be run. In the program first open the software. Open the project. Hello world program code can be write in java. Build the project. Run the project. In the output the mobile or media control can be display the text field phone number in

    first mobile.

    In the second mobile we can enter the phone number Finally output can be displayed in the mobile.

  • 8/13/2019 Mobile application development lab

    21/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 21

    SOURCE CODE:

    import javax.microedition.lcdui.*;

    import javax.microedition.lcdui.Command;

    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.midlet.MIDlet;

    import java.lang.*;

    public class PhnoValidation extends MIDlet implements CommandListener

    {

    Display dis;

    Form f;

    TextField num;

    StringItem res,res1;

    Command ex,vw,clr,help;

    int id,idx;

    String s,s1,s2;

    public void startApp()

    {

    dis=Display.getDisplay(this);

    f=new Form("Phone no.Validation");

    num=new TextField("Enter Phone number","*******",30,TextField.ANY);

    vw=new Command("validate",Command.SCREEN,2);

    ex=new Command("exit",Command.EXIT,2);

    clr=new Command("clear",Command.SCREEN,2);

    help=new Command("help",Command.SCREEN,2);

    res=new StringItem(null,null);res1=new StringItem(null,null);

    f.append(num);

    f.append(res);

    f.append(res1);

    f.addCommand(ex);

    f.addCommand(vw);

    f.addCommand(clr);f.addCommand(help);

    f.setCommandListener(this);

  • 8/13/2019 Mobile application development lab

    22/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 22

    dis.setCurrent(f);

    }

    public void pauseApp()

    {

    }

    public void destroyApp(boolean cond)

    {

    }

    public void commandAction(Command c,Displayable d)

    {

    if(c==ex)

    {

    destroyApp(true);

    notifyDestroyed();

    }

    else if(c==vw)

    {

    s=num.getString();

    idx=s.indexOf("-");

    if(idx!=3&&idx!=4)

    {res.setText(s+" is a invalid ph.no.click help to see a exapmle ph.no.");

    }

    else

    {

    s1=s.substring(0,idx);

    s2=s.substring(idx+1,s.length());

    if(s2.length()8)

    {

    res.setText(s+" is a invalid ph.no.click help to see a exapmle ph.no.");

  • 8/13/2019 Mobile application development lab

    23/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 23

    }

    else if(s1.equals("040")||s1.equals("050")||s1.equals("041")||s1.equals("0400"))

    {

    res.setText(s+" is a valid ph.no");

    }

    else

    {

    res.setText(s+" is a invalid ph.no.click help to see a exapmle ph.no.");

    }

    }

    }

    else if(c==clr)

    {

    num.setString("");

    res.setText("");

    res1.setText("");

    }

    else if(c==help)

    {

    res1.setText("The area code should be 040 or 050 or 041 or 0400 and ph.no should consist of 6-

    8 digits like 040-12345678");

    }

    }

    }

  • 8/13/2019 Mobile application development lab

    24/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 24

    Output:

  • 8/13/2019 Mobile application development lab

    25/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 25

    Introduction to the Android:

    What is Android:

    Android is an open source and Linux-based Operating Systemfor mobile devices such as

    smartphones and tablet computers. Android was developed by the Open Handset Alliance, led byGoogle, and other companies. Android offers a unified approach to application development for

    mobile devices which means developers need only develop for Android, and their applications

    should be able to run on different devices powered by Android. The first beta version of the

    Android Software Development Kit (SDK) was released by Google in 2007 where as the first

    commercial version, Android 1.0, was released in September 2008. On June 27, 2012, at the

    Google I/O conference, Google announced the next Android version, 4.1 Jelly Bean. Jelly Bean

    is an incremental update, with the primary aim of improving the user interface, both in terms of

    functionality and performance. The source code for Android is available under free and open

    source software licenses. Google publishes most of the code under the Apache License version

    2.0 and the rest, Linux kernel changes, under the GNU General Public License version 2.

    Android Architecture:

    Android operating system is a stack of software components which is roughly divided into five

    sections and four main layers as shown below in the architecture diagram.

    Installing Android SDK:

    Step 1:Installing Eclipse IDE on computer.1. First you can download eclipse from above link.2. Then extract it to you preferred directory.3. After that you can go to installed directory then run eclipse.exe

    Step 2: Installing Android SDK starter package on computer:

    1. First you can download SDK form above link. The recommended one is marked byred in following screen shot

    Fig 1: SDK to download.

    https://lh5.googleusercontent.com/-4e24kf1REtI/TYejeDgdbEI/AAAAAAAAAdc/rCo1NqfeX2c/s1600/sdk+downloading.PNGhttps://lh5.googleusercontent.com/-4e24kf1REtI/TYejeDgdbEI/AAAAAAAAAdc/rCo1NqfeX2c/s1600/sdk+downloading.PNG
  • 8/13/2019 Mobile application development lab

    26/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 26

    2. Then run this installer, it will install Android SDK for you.3. After you install SDK go to the installed directory then run SDK Manager.exe

    Fig 2: SDK manager with installed component.

    4. Then you can see above window this is Android SDK and AVD Manager.Nextthing is you have to install some component to using this for Android development.the

    Following table shows recommended component to install.

    5. To install those component click Available packages menu in left panel onAndroid SDK and AVD Manager.Then select those component then click install selected

    button bellow.

    Fig 3: Available package to install.

    6. Then close the SDK manager.that's all for installing SDKStep 3: Installing ADT plugin for Eclipse.

    1. First Start the Eclipse IDE that you installed.2. Then go toHelp > Install New Software... and click Add..Button in right-top. Itwill appear following window.

    Fig 4: Add repository

    https://lh5.googleusercontent.com/-8jbWTEoCW60/TYyTCRZHGbI/AAAAAAAAAdo/XEBQ_P30Ibo/s1600/add+repo.PNGhttps://lh3.googleusercontent.com/-ic3Z9R8OCn0/TYyKHXSpRQI/AAAAAAAAAdk/vVVoMr00Wqs/s1600/AVD+avalable+package.PNGhttps://lh4.googleusercontent.com/-ZB0dk6_qptU/TYemWjEGZMI/AAAAAAAAAdg/P-SUKBcwz_0/s1600/SDK+Manager.PNGhttps://lh5.googleusercontent.com/-8jbWTEoCW60/TYyTCRZHGbI/AAAAAAAAAdo/XEBQ_P30Ibo/s1600/add+repo.PNGhttps://lh3.googleusercontent.com/-ic3Z9R8OCn0/TYyKHXSpRQI/AAAAAAAAAdk/vVVoMr00Wqs/s1600/AVD+avalable+package.PNGhttps://lh4.googleusercontent.com/-ZB0dk6_qptU/TYemWjEGZMI/AAAAAAAAAdg/P-SUKBcwz_0/s1600/SDK+Manager.PNGhttps://lh5.googleusercontent.com/-8jbWTEoCW60/TYyTCRZHGbI/AAAAAAAAAdo/XEBQ_P30Ibo/s1600/add+repo.PNGhttps://lh3.googleusercontent.com/-ic3Z9R8OCn0/TYyKHXSpRQI/AAAAAAAAAdk/vVVoMr00Wqs/s1600/AVD+avalable+package.PNGhttps://lh4.googleusercontent.com/-ZB0dk6_qptU/TYemWjEGZMI/AAAAAAAAAdg/P-SUKBcwz_0/s1600/SDK+Manager.PNG
  • 8/13/2019 Mobile application development lab

    27/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 27

    3. then add following detail and click OKbuttonName As you wish (exp:-ADT)

    Location https://dl-ssl.google.com/android/eclipse/

    4. Then it shows Available Software dialog, then select Developer Toolsandclick Nextbutton.

    5. Next you can see software package to be installed.so click Nextbutton6. Then read license agreements and accept it then click Finish.7. After complete installation restart Eclipse IDE.8. Then go to Windows > Preferences..to open preferences panel.

    Fig 5:Set SDK Location

    9. In left panel click Android10. For the SDK Location in the panel, locate your SDK directoryusing Browse...button.

    11. Finally Click on Apply, then OKAfter you install ADT plugin for Eclipse the following toolbar appear on Eclipse IDE.

    Fig 6: Android toolbar

    The highlighted icon is use for lunching Android SDK and AVD Manager.

    https://dl-ssl.google.com/android/eclipse/https://dl-ssl.google.com/android/eclipse/https://lh5.googleusercontent.com/-lpnzCUJfPZo/TYycs-4JqsI/AAAAAAAAAdw/VDpdTHeXd9A/s1600/androidtoolbar.PNGhttps://lh3.googleusercontent.com/-fuXod14TUUw/TYya6xgbiGI/AAAAAAAAAds/hDxUDA85PLA/s1600/setpath.PNGhttps://lh5.googleusercontent.com/-lpnzCUJfPZo/TYycs-4JqsI/AAAAAAAAAdw/VDpdTHeXd9A/s1600/androidtoolbar.PNGhttps://lh3.googleusercontent.com/-fuXod14TUUw/TYya6xgbiGI/AAAAAAAAAds/hDxUDA85PLA/s1600/setpath.PNGhttps://dl-ssl.google.com/android/eclipse/
  • 8/13/2019 Mobile application development lab

    28/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 28

    WEEK-10

    Aim:Write a android application program that displays using Hello Worldeclipse?

    Description:

    To run any application in ecllipse first we have to install java6. Create a new application. Go to file menu. Select new and then select Android Mobile Application. A window appear after selecting then full the fields in the window i.e giving the

    application name.

    Click next button and complete all the windows by clicking next-button until we see thefinishbutton.

    Once we click an finish button if will open a window where we actually write ourapplication.

    To write android applications , Activity is very important i.e Activity.main.xml.file. These files are present at left corner of the window.

    Reslayout- Activity.Main.java.

  • 8/13/2019 Mobile application development lab

    29/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 29

    SOURCE CODE:

    package com.example.hai;

    import android.os.Bundle;

    import android.app.Activity;

    import android.view.Menu;

    public class MainActivity extends Activity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    }

    }

    Layout:

    activity_main .xml:

  • 8/13/2019 Mobile application development lab

    30/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 30

    Output:

  • 8/13/2019 Mobile application development lab

    31/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 31

    WEEK-11

    Aim: Write a android application program that accepts a name from user and displays theHello name to the user in response as output using eclipse?

    Description:

    Create a new application and name it as wek2. Now select the option text field from the palette window and drag the abc notation option

    and drop on to the window.

    Select button from the palette and drag the button and drop on to the window. Save the window which we design and write the related code in the Main Activity.java. Save the java code and run the program. Now the output is displayed on the emulator which are created.

  • 8/13/2019 Mobile application development lab

    32/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 32

    SOURCE CODE:

    package com.example.wek2;

    import android.os.Bundle;

    import android.app.Activity;

    import android.view.Menu;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.widget.Button;

    import android.widget.EditText;

    import android.widget.Toast;

    public class MainActivity extends Activity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    final String s = "Hello ";

    Button clickButton = (Button) findViewById(R.id.button1);

    final EditText changeEditText = (EditText) findViewById(R.id.editText1);

    clickButton.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View arg0) {// TODO Auto-generated method stub

    Toast.makeText(getApplicationContext(),

    s+changeEditText.getText().toString(), Toast.LENGTH_LONG).show();

    }

    });

    }

    }

  • 8/13/2019 Mobile application development lab

    33/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 33

    Layout:

    activity_main .xml:

  • 8/13/2019 Mobile application development lab

    34/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 34

    Output:

  • 8/13/2019 Mobile application development lab

    35/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 35

    WEEK-12

    Aim: Write a android application program that demonstrates the following?i) Linear Layout

    ii)Relative Layout

    iii)Table Layout

    iv)Grid Layout

    Description:

    Create a new application and name it as layouts. Now select the option text field from the palette window and drag the abc notation

    option and drop on to the window.

    Select button from the palette and drag the button and drop on to the window. In the graphical layout drag five buttons. When the buttons are on the screen, check it with the four layouts. The four layouts are linear,relative table,grid layouts. Each layout represent its output in different relations. Finally all layouts can be displayed in one output. Save the window which we design and write the related code in the Main Activity.java. Save the java code and run the program. Now the output is displayed on the emulator which are created.

  • 8/13/2019 Mobile application development lab

    36/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 36

    SOURCE CODE:

  • 8/13/2019 Mobile application development lab

    37/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 37

    android:layout_gravity="left"/>

  • 8/13/2019 Mobile application development lab

    38/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 38

    android:layout_column="1"

    android:layout_gravity="fill_vertical"

    android:layout_marginLeft="297dp"

    android:layout_row="6"

    android:layout_toRightOf="@+id/quickContactBadge3"/>

    Output:

  • 8/13/2019 Mobile application development lab

    39/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 39

    SOURCE CODE:

  • 8/13/2019 Mobile application development lab

    40/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 40

    android:id="@+id/quickContactBadge6"

    android:layout_column="0"

    android:layout_gravity="left"/>

    Output:

  • 8/13/2019 Mobile application development lab

    41/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 41

    SOURCE CODE:

  • 8/13/2019 Mobile application development lab

    42/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 42

    Output:

  • 8/13/2019 Mobile application development lab

    43/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 43

    SOURCE CODE:

  • 8/13/2019 Mobile application development lab

    44/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 44

    vertical

    Output:

  • 8/13/2019 Mobile application development lab

    45/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 45

    SOURCE CODE:

  • 8/13/2019 Mobile application development lab

    46/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 46

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_gravity="left"/>

    Output:

  • 8/13/2019 Mobile application development lab

    47/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 47

    SOURCE CODE:

  • 8/13/2019 Mobile application development lab

    48/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 48

    Output:

  • 8/13/2019 Mobile application development lab

    49/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 49

    WEEK-13

    Aim: Write a android application program that converts the temperature in Celsius toFarenheit?

    Description:

    Create a new application and name it as temperature. Now select the option text field from the palette window and drag the abc notation

    option,two radio buttons,one button and drop on to the window.

    Select button from the palette and drag the button and drop on to the window. In the output when we click the button with mouse the page can be shift to the next page . In the next page enter the temperature value in the empty field box, than select the option

    either Celsius to Farenheit.

    Press the button it will show the temperature will converts the Celsius to Farenheit. Save the window which we design and write the related code in the Main Activity.java. Save the java code and run the program. Now the output is displayed on the emulator which are created.

  • 8/13/2019 Mobile application development lab

    50/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 50

    SOURCE CODE:package com.example.converttemperatureexample;

    import android.app.Activity;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.EditText;

    import android.widget.RadioButton;

    import android.widget.Toast;

    public class ConvertTempertureExample extends Activity {

    private EditText text;

    @Override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    text = (EditText) findViewById(R.id.editText1);

    }

    // This method is called at button click because we assigned the name to the

    // "On Click property" of the button

    public void myClickHandler(View view) {

    switch (view.getId()) {

    case R.id.button1:

    RadioButton celsiusButton = (RadioButton)findViewById(R.id.radio0);

    RadioButton fahrenheitButton = (RadioButton)findViewById(R.id.radio1);

    if (text.getText().length() == 0) {

    Toast.makeText(this, "Please enter a valid number",Toast.LENGTH_LONG).show();

    return;

    }

    float inputValue =Float.parseFloat(text.getText().toString());

    if (celsiusButton.isChecked()) {

    text.setText(String

    .valueOf(convertFahrenheitToCelsius(inputValue)));celsiusButton.setChecked(false);

    fahrenheitButton.setChecked(true);

  • 8/13/2019 Mobile application development lab

    51/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 51

    } else {

    text.setText(String

    .valueOf(convertCelsiusToFahrenheit(inputValue)));

    fahrenheitButton.setChecked(false);

    celsiusButton.setChecked(true);

    }

    break;

    }

    }

    // Converts to celsius

    private float convertFahrenheitToCelsius(float fahrenheit) {

    return ((fahrenheit - 32) * 5 / 9);

    }

    // Converts to fahrenheit

    private float convertCelsiusToFahrenheit(float celsius) {

    return ((celsius * 9) / 5) + 32;

    }

    }

    Layout:

  • 8/13/2019 Mobile application development lab

    52/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 52

    android:id="@+id/radioGroup1"

    android:layout_width="match_parent"

    android:layout_height="wrap_content" >

    My Style.xml :

  • 8/13/2019 Mobile application development lab

    53/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 53

    Strings.xml :

    Hello world!

    Settings

    ConvertTempertureExample

    Temparature Converter

    #3399CC

    myClickHandler

    to Celsius

    to Fahrenheit

    Calculate

  • 8/13/2019 Mobile application development lab

    54/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 54

    Output:

  • 8/13/2019 Mobile application development lab

    55/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 55

    WEEK-14

    Aim: Write a android application program that demonstrates Intent in MobileApplication Development?

    Description:

    Create a new application and name it as intent. Now select the option text field from the palette window and drag the abc notation option

    and drop on to the window.

    Select button from the palette and drag the button and drop on to the window. In the output when we click the button with mouse the page can be shift to the next page

    or gallery page.

    In the Gallery images cannot be find, but it will shows no images found, because theemulator having default settings.

    Save the window which we design and write the related code in the Main Activity.java. Save the java code and run the program. Now the output is displayed on the emulator which are created.

  • 8/13/2019 Mobile application development lab

    56/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 56

    SOURCE CODE:

    package com.example.intent;

    import android.os.Bundle;

    import android.app.Activity;

    import android.content.Intent;

    import android.view.Menu;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.widget.Button;

    public class MainActivity extends Activity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    Button nextButton = (Button)findViewById(R.id.button1);

    nextButton.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View arg0) {

    // TODO Auto-generated method stub

    Intent i = new Intent(Intent.ACTION_VIEW);

    i.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);

    startActivity(i);

    //startActivity(i);

    }

    });

    }

  • 8/13/2019 Mobile application development lab

    57/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 57

    }

    Layout:

    activity_main .xml:

  • 8/13/2019 Mobile application development lab

    58/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 58

    Output:

  • 8/13/2019 Mobile application development lab

    59/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 59

    ADDITIONAL PROGRAM

    Aim: Write a android application program that demonstrates button in MobileApplication Development?

    Description:

    Create a new application and name it as button. Now select the one button from the palette window and drag the checkbox and drop on to

    the window.

    Select button from the palette and drag the button and drop on to the window. In the output when we click the button with mouse the page can be shift to the next page

    and it will display the dietakp website.

    In that website it will display in the output,webpage is not available because the emulatorhaving default settings and the net connection is not used for the emulator.

    Save the window which we design and write the related code in the Main Activity.java. Save the java code and run the program. Now the output is displayed on the emulator which are created.

  • 8/13/2019 Mobile application development lab

    60/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 60

    SOURCE CODE:

    package com.example.bu;

    import android.os.Bundle;

    import android.app.Activity;

    import android.view.Menu;

    import android.app.Activity;

    import android.content.Intent;

    import android.net.Uri;

    import android.os.Bundle;

    import android.widget.Button;

    import android.view.View;

    import android.view.View.OnClickListener;

    public class MainActivity extends Activity {

    Button button;

    @Override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    addListenerOnButton();

    }

    public void addListenerOnButton() {

    button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View arg0) {

  • 8/13/2019 Mobile application development lab

    61/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    ROLL NO: 10U41A1224 Page 61

    Intent browserIntent = new Intent(Intent.ACTION_VIEW,

    Uri.parse("http://www.dietakp.com"));

    startActivity(browserIntent);

    } });}}

    Layout:

    activity_main .xml:

  • 8/13/2019 Mobile application development lab

    62/62

    MOBILE APPLICATION DEVELOPMENT LAB RECORD

    Output: