Sei sulla pagina 1di 62

MOBILE APPLICATION DEVELOPMENT LAB RECORD

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 the Embedded 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 programming interfaces for the small computing device 3. Configurations: Which handles interactions between the profile and the JVM? 4. JVM 5. 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.

ROLL NO: 10U41A1224

Page 1

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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.

ROLL NO: 10U41A1224

Page 2

MOBILE APPLICATION DEVELOPMENT LAB RECORD

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 called KToolbarif you'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 the name 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 a minute. Write your Java source in your favorite editor or IDE (or copy existing code) and save into The src 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.

ROLL NO: 10U41A1224

Page 3

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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.

ROLL NO: 10U41A1224

Page 4

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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(); } }

ROLL NO: 10U41A1224

Page 5

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 6

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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 displayed in second mobile. Finally output can be displayed in the mobile.

ROLL NO: 10U41A1224

Page 7

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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) {} }

ROLL NO: 10U41A1224

Page 8

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 9

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Week -3 Aim: Create a J2ME menu which has the following options(Event Handling):
Cut can be on/off Copy can be on/off paste can be on/off delete can be on/off select all pull 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 displayed in second mobile. Finally output can be displayed in the mobile.

ROLL NO: 10U41A1224

Page 10

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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);
ROLL NO: 10U41A1224 Page 11

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Back=new Command("Back",Command.BACK,1); form.addCommand(View); form.addCommand(Exit); form1.addCommand(Back); form.setCommandListener(this); form1.setCommandListener(this); form.setItemStateListener(this); } 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==View) { boolean opt[]=new boolean[ch.size()]; st=new StringItem(" "," "); String values=" "; ch.getSelectedFlags(opt); for(int i=0;i<opt.length;i++) { if(opt[i]) { values+=ch.getString(i)+"\n"; } } st.setText(values);
ROLL NO: 10U41A1224 Page 12

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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<size) { if(ch1.getSelectedIndex()==0) ch.setSelectedIndex(i,true); else ch.setSelectedIndex(i,false); i++; } } }

ROLL NO: 10U41A1224

Page 13

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 14

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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.

ROLL NO: 10U41A1224

Page 15

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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); }
ROLL NO: 10U41A1224 Page 16

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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); }
ROLL NO: 10U41A1224 Page 17

MOBILE APPLICATION DEVELOPMENT LAB RECORD


} } 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<data.length) { y=data[i]; h=200+y1-y; g.fillRect(x,y,25,h); x+=30; i++; } } }

ROLL NO: 10U41A1224

Page 18

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 19

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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.

ROLL NO: 10U41A1224

Page 20

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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);
ROLL NO: 10U41A1224 Page 21

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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()<6||s2.length()>8) { res.setText(s+" is a invalid ph.no.click help to see a exapmle ph.no.");
ROLL NO: 10U41A1224 Page 22

MOBILE APPLICATION DEVELOPMENT LAB RECORD


} 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 68 digits like 040-12345678"); } } }

ROLL NO: 10U41A1224

Page 23

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 24

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Introduction to the Android: What is Android:
Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, 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 by red in following screen shot

Fig 1: SDK to download.


ROLL NO: 10U41A1224 Page 25

MOBILE APPLICATION DEVELOPMENT LAB RECORD


2. 3. Then run this installer, it will install Android SDK for you. 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.Next thing 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 on Android SDK and AVD Manager.Then select those component then click install selected button bellow.

6.

Fig 3: Available package to install. Then close the SDK manager.that's all for installing SDK

Step 3: Installing ADT plugin for Eclipse. 1. First Start the Eclipse IDE that you installed. 2. Then go to Help > Install New Software... and click Add.. Button in right-top. It will appear following window.

Fig 4: Add repository


ROLL NO: 10U41A1224 Page 26

MOBILE APPLICATION DEVELOPMENT LAB RECORD


3. Name Location then add following detail and click OK button As you wish (exp:-ADT) https://dl-ssl.google.com/android/eclipse/

4. Then it shows Available Software dialog, then select Developer Tools and click Next button. 5. Next you can see software package to be installed.so click Next button 6. 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 Android 10. For the SDK Location in the panel, locate your SDK directory using Browse... button. 11. Finally Click on Apply, then OK After 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.

ROLL NO: 10U41A1224

Page 27

MOBILE APPLICATION DEVELOPMENT LAB RECORD


WEEK-10 Aim: Write a android application program that displays using Hello World eclipse? 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 the finish button. Once we click an finish button if will open a window where we actually write our application. To write android applications , Activity is very important i.e Activity.main.xml.file. These files are present at left corner of the window. Res layout- Activity.Main.java.

ROLL NO: 10U41A1224

Page 28

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" />

</RelativeLayout>
ROLL NO: 10U41A1224 Page 29

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 30

MOBILE APPLICATION DEVELOPMENT LAB RECORD


WEEK-11 Aim: Write a android application program that accepts a name from user and displays the
Hello 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.

ROLL NO: 10U41A1224

Page 31

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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(); } }); }

}
ROLL NO: 10U41A1224 Page 32

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Layout: activity_main .xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="94dp" android:text="Button" />

<EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button1" android:layout_centerHorizontal="true" android:layout_marginBottom="138dp" android:ems="10" />

ROLL NO: 10U41A1224

Page 33

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 34

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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.

ROLL NO: 10U41A1224

Page 35

MOBILE APPLICATION DEVELOPMENT LAB RECORD


SOURCE CODE:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/RelativeLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:columnCount="2" android:orientation="horizontal" tools:context=".MainActivity" >

<QuickContactBadge android:id="@+id/quickContactBadge3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/quickContactBadge3" android:layout_below="@+id/quickContactBadge3" android:layout_column="0" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/quickContactBadge3" android:layout_below="@+id/quickContactBadge2" android:layout_column="0"


ROLL NO: 10U41A1224 Page 36

MOBILE APPLICATION DEVELOPMENT LAB RECORD


android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/quickContactBadge3" android:layout_below="@+id/quickContactBadge1" android:layout_column="0" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/quickContactBadge3" android:layout_below="@+id/quickContactBadge4" android:layout_column="0" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/quickContactBadge3" android:layout_below="@+id/quickContactBadge5" android:layout_column="0" android:layout_gravity="left" />

<LiSpace android:id="@+id/LiSpace1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/quickContactBadge6"


ROLL NO: 10U41A1224 Page 37

MOBILE APPLICATION DEVELOPMENT LAB RECORD


android:layout_column="1" android:layout_gravity="fill_vertical" android:layout_marginLeft="297dp" android:layout_row="6" android:layout_toRightOf="@+id/quickContactBadge3" />

</RelativeLayout>

Output:

ROLL NO: 10U41A1224

Page 38

MOBILE APPLICATION DEVELOPMENT LAB RECORD


SOURCE CODE:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/GridLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:columnCount="2" android:orientation="horizontal" tools:context=".MainActivity" >

<QuickContactBadge android:id="@+id/quickContactBadge3" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge2" android:layout_column="0" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge1" android:layout_column="0" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge4" android:layout_column="0" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge5" android:layout_column="0" android:layout_gravity="left" /> <QuickContactBadge


ROLL NO: 10U41A1224 Page 39

MOBILE APPLICATION DEVELOPMENT LAB RECORD


android:id="@+id/quickContactBadge6" android:layout_column="0" android:layout_gravity="left" />

<LiSpace android:id="@+id/LiSpace1" android:layout_column="1" android:layout_gravity="fill_vertical" android:layout_marginLeft="297dp" android:layout_row="6" /> </GridLayout>

Output:

ROLL NO: 10U41A1224

Page 40

MOBILE APPLICATION DEVELOPMENT LAB RECORD


SOURCE CODE:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".MainActivity" >

<QuickContactBadge android:id="@+id/quickContactBadge3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

ROLL NO: 10U41A1224

Page 41

MOBILE APPLICATION DEVELOPMENT LAB RECORD


<QuickContactBadge android:id="@+id/quickContactBadge5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<LiSpace android:id="@+id/LiSpace1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_vertical" android:layout_marginLeft="446dp" />

</LinearLayout>

Output:

ROLL NO: 10U41A1224

Page 42

MOBILE APPLICATION DEVELOPMENT LAB RECORD


SOURCE CODE:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" >

<QuickContactBadge android:id="@+id/quickContactBadge3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

ROLL NO: 10U41A1224

Page 43

MOBILE APPLICATION DEVELOPMENT LAB RECORD


<QuickContactBadge android:id="@+id/quickContactBadge5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<LiSpace android:id="@+id/LiSpace1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_vertical" android:layout_marginLeft="446dp" />

</LinearLayout>vertical

Output:

ROLL NO: 10U41A1224

Page 44

MOBILE APPLICATION DEVELOPMENT LAB RECORD


SOURCE CODE:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/TableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >

<QuickContactBadge android:id="@+id/quickContactBadge3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge5"
ROLL NO: 10U41A1224 Page 45

MOBILE APPLICATION DEVELOPMENT LAB RECORD


android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<LiSpace android:id="@+id/LiSpace1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_vertical" android:layout_marginLeft="446dp" />

</TableLayout>

Output:

ROLL NO: 10U41A1224

Page 46

MOBILE APPLICATION DEVELOPMENT LAB RECORD


SOURCE CODE:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/TableRow1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" >

<QuickContactBadge android:id="@+id/quickContactBadge3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

ROLL NO: 10U41A1224

Page 47

MOBILE APPLICATION DEVELOPMENT LAB RECORD


<QuickContactBadge android:id="@+id/quickContactBadge5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<QuickContactBadge android:id="@+id/quickContactBadge6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" />

<LiSpace android:id="@+id/LiSpace1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_vertical" android:layout_marginLeft="446dp" /> </TableRow>

Output:

ROLL NO: 10U41A1224

Page 48

MOBILE APPLICATION DEVELOPMENT LAB RECORD


WEEK-13 Aim: Write a android application program that converts the temperature in Celsius to
Farenheit?

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.

ROLL NO: 10U41A1224

Page 49

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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);
ROLL NO: 10U41A1224 Page 50

MOBILE APPLICATION DEVELOPMENT LAB RECORD


} 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:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/myshape" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" > </EditText> <RadioGroup
ROLL NO: 10U41A1224 Page 51

MOBILE APPLICATION DEVELOPMENT LAB RECORD


android:id="@+id/radioGroup1" android:layout_width="match_parent" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="@string/celsius" > </RadioButton> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fahrenheit" > </RadioButton> </RadioGroup> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/calc" android:onClick="myClickHandler"> </Button> </LinearLayout>

My Style.xml :
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <stroke android:width="2dp" android:color="#FFFFFFFF" />
ROLL NO: 10U41A1224 Page 52

MOBILE APPLICATION DEVELOPMENT LAB RECORD


<gradient android:endColor="#DDBBBBBB" android:startColor="#DD777777" android:angle="90" /> <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" /> </shape>

Strings.xml :
<resources> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="title_activity_convert_temperture_example">ConvertTempertureExample</string> <string name="app_name">Temparature Converter</string> <color name="myColor">#3399CC</color> <string name="myClickHandler">myClickHandler</string> <string name="celsius">to Celsius</string> <string name="fahrenheit">to Fahrenheit</string> <string name="calc">Calculate</string> </resources>

ROLL NO: 10U41A1224

Page 53

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 54

MOBILE APPLICATION DEVELOPMENT LAB RECORD


WEEK-14 Aim: Write a android application program that demonstrates Intent in Mobile
Application 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 the emulator 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.

ROLL NO: 10U41A1224

Page 55

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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);

} }); }

ROLL NO: 10U41A1224

Page 56

MOBILE APPLICATION DEVELOPMENT LAB RECORD


}

Layout: activity_main .xml:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="123dp" android:text="Button" />

<EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="59dp" android:ems="10" >

ROLL NO: 10U41A1224

Page 57

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 58

MOBILE APPLICATION DEVELOPMENT LAB RECORD


ADDITIONAL PROGRAM Aim: Write a android application program that demonstrates button in Mobile
Application 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 emulator having 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.

ROLL NO: 10U41A1224

Page 59

MOBILE APPLICATION DEVELOPMENT LAB RECORD


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) {


ROLL NO: 10U41A1224 Page 60

MOBILE APPLICATION DEVELOPMENT LAB RECORD

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.dietakp.com")); startActivity(browserIntent);

} });}}

Layout: activity_main .xml:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="142dp" android:text="Button" />

<EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:ems="10" />


ROLL NO: 10U41A1224 Page 61

MOBILE APPLICATION DEVELOPMENT LAB RECORD


Output:

ROLL NO: 10U41A1224

Page 62

Potrebbero piacerti anche