Mobile Application Development Lab
Mobile Application Development Lab
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.
Page 1
Page 2
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.
Page 3
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.
Page 4
public class HelloWorld extends MIDlet implements CommandListener { public void startApp() { Display display = Display.getDisplay(this);
display.setCurrent(mainForm); }
Page 5
Page 6
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.
Page 7
Page 8
Page 9
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.
Page 10
Page 13
Page 14
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.
Page 15
Page 18
Page 19
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.
Page 20
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
Page 23
Page 24
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.
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 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.
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.
Page 27
Page 28
</RelativeLayout>
ROLL NO: 10U41A1224 Page 29
Page 30
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.
Page 31
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;
@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
Page 33
Page 34
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.
Page 35
</RelativeLayout>
Output:
Page 38
Output:
Page 40
Page 41
</LinearLayout>
Output:
Page 42
Page 43
</LinearLayout>vertical
Output:
Page 44
<QuickContactBadge android:id="@+id/quickContactBadge5"
ROLL NO: 10U41A1224 Page 45
</TableLayout>
Output:
Page 46
Page 47
Output:
Page 48
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.
Page 49
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
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
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>
Page 53
Page 54
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.
Page 55
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;
@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);
} }); }
Page 56
Page 57
Page 58
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.
Page 59
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;
Button button;
addListenerOnButton();
button.setOnClickListener(new OnClickListener() {
} });}}
Page 62