You are on page 1of 20

J2ME implementation

in Mobile App Project


development for Java
enabled CLDCs
Report

M Yasir Khan (Trainee)


A Section 25 company
B.Tech (Electronics & Communication)
Faculty of Engineering & Technology Department of Electronics & IT
Jamia Millia Islamia University Ministry of Communication & IT
New Delhi Government of India
A Summer Training Project
on
J2ME implementation in Mobile app
development for Java™ enabled CLDCs

( May 2012 – June 2012 )


TABLE OF CONTENTS

 Abstract

 Acknowledgement

 Introduction of Media Lab Asia

 Work Report

 Project Details
o An Overview
o MODULE 1- Getting Started
o MODULE 2- Video Player & Listing Application
o MODULE 3- Export to Mobile Handset

 References

 Useful Links

 Software Used

 Hardware Used
ABSTRACT

Java Platform, Micro Edition (Java ME) provides a robust, flexible


environment for applications running on mobile and other embedded
devices: mobile phones, personal digital assistants (PDAs), TV set-top
boxes, and printers. Java ME includes flexible user interfaces, robust
security, built-in network protocols, and support for networked and
offline applications that can be downloaded dynamically. Applications
based on Java ME are portable across many devices, yet leverage
each device's native capabilities.

My task was to develop a code for Video Player & Search application
for implementation in Java enabled handsets. Working in the Media Lab
Asia I too learnt about other on-going projects in Media lab such as one
in collaboration with IIT Bombay, e-Galla, a retail management software
enabling ICT for Livelihood Enhancement
ACKNOWLEDGEMENT

I take this this opportunity to thank Dr. T S Anurag and Mr. Anshul
Porwal for their valuable guidance, closely supervising my work on the
project “J2ME implementation in Mobile App development for Java
enabled CLDCs”.

I sincerely thank and grateful to Dr. T S Anurag who guided me and


introduced me to the project of ICT in Agriculture. I am also grateful to
Mr. Anshul Porwal under whose supervision, the project was structured,
also thankful for always useful help from Mr. Satyavir Singh and Mr.
Giridhari Kumar.
INTRODUCTION OF MEDIA LAB ASIA
Media Lab Asia has been promoted by Department of Electronics and
Information technology, MCIT, Govt. of India as a not for profit
company. The objective of the company was set to bring the benefits of
ICT to the common man. It started with the functional activity areas
such as World Computer (Affordable, ubiquitous computing and access
devices), Bits for All (Low Cost, High bandwidth connectivity) and
Tomorrow's Tool (Rurally relevant applications). However it was later
changed to application areas such as ICT for Healthcare, Education,
Livelihood and Empowerment of Disabled.
Since then the company has taken up 75 development projects and
some of the projects are now being rolled out at the national level. The
company has a unique way of growth by working with an expanding
network of research laboratories for undertaking development work. It
started with creating a hub at some of the IITs and the list of such
project partners has grown to more than 58. The partners are a
combination of academic and Research and Development institutions,
industry, NGOs and Govt. Agencies. The projects can be sponsored by
Corporate Bodies, Govt. (Central/State) and Local Municipal
Bodies/Panchayats etc.
After development the technology is taken from lab to land for pilot
testing/ large scale deployment through a unique scheme of
provider/user membership under PPP model. MLAsia is poised for
developing relevant and sustainable technologies and culturally
appropriate solutions touching daily lives of common people in years to
come.
Media Lab Asia has embarked on an adventurous plan for meeting the
grand challenges in bringing the benefits of quality ICT technologies in
the areas of Healthcare, Education, Empowerment of the disabled,
Village Livelihood Generation and Rural Connectivity, keeping in view
the need to operate in local languages and to support local culture and
tradition, by empowering people at grassroot level forming collaborative
efforts with R&D laboratories, Industry, NGOs and Government.
While perusing the above objectives, the company has currently
focused on the following application areas:
 Healthcare
 Education including technical and vocational courses
 Empowerment of the disabled
 Village livelihood generation
WORK REPORT

DAY 1:
Introduction to the employees of the Media Lab Asia.

DAY 2:
I got to study about the Java platforms such as J2EE, J2SE, J2ME and got a look of
some earlier projects undertaken by the Media Lab. Downloaded and installed
Android SDKs, Java Eclipse.

DAY 3:
Got introduced to the Java Environment for programming, did some amateur
programs on Eclipse.

DAY 4:
Did some advanced programs brushing the java knowledge.

DAY 5:
Studied about MIDP programming in J2ME for Java App requirement in eKrishi
project for JRE enabled phones.

DAY 6:
Learnt about developing a basic mobile app, such as one to display "hello world".
How to run basic programs on Eclipse IDE, and Wireless Toolkit

DAY 7:
Still learning about compiling and running fundamental java programs.

DAY 8:
Assigned a task of developing an app for Java enabled phones to display a photo
album.

DAY 9:
The MIDlet program for the photo album runs successfully on the emulator, and the
the task is accomplished.

DAY 10:
Assigned a task of developing a searchbox based Database connection in J2ME.

DAY 11:
Learning how to retrieve information from a database in an application.

DAY 12:
Saw some basic programs on File import from Database System, and learnt the
login page development programming in J2ME.

DAY 13:
Learnt to define a user and database interface in J2ME java platform.
DAY 14:
Learnt how to install an operating system on office based systems such as Ubuntu,
Windows and the various drivers required for the functioning of applications.

DAY 15:
Learnt about an ongoing project at Media lab in collaboration with IIT Bombay, e-
Galla, a retail management software enabling ICT for Livelihood Enhancement.
The main features of the project are:
# Artisans can make embroidery designs using computers
# Designs can be stored, reused and combined in various ways to create new
designs.
e-Galla is basically for Small Shops and Enterprises

DAY 16:
Learnt to use NetBeans IDE for compiling and running simple Java Applications.
Version used Oracle NetBeans IDE 6.9

DAY 17:
Using NetBeans IDE for Mobile Applications development in J2ME platform.
Using the Drag and Drop features of the IDE to create VisualMIDlets for interactive
User Interface (UI).

DAY 18:
Learnt using visual MIDlets, and importing files.

DAY 19:
Learnt some basic features of DBMS, Content Management system( CMS )
Features of CMS, types of CMS, Content Management Framework, how CMS is
implied using Joomla, WordPress.

DAY 20:
Revised my HTML concepts and the use of JavaScript to manipulate existing HTML
elements.
learnt few basics of mySQL. And how a Client side and Server Side programming
works.

DAY 21:
Did testing of an on-going project "KRISHI PRASAAR SEVA -Integrated
Information Dissemination System " on its portal.

DAY 22:
Registered and approved the Expert Side User for the portal KRISHI PRASAAR
SEVA, tested the flow of information from farmer to expert, and solutions provided
by expert to farmer.

DAY 23:
Work on the J2ME coding still in progress.

DAY 24:
Completed the codings, the Video player app runs on the Emulator, prepared the
jar file to run the application on mobile
DAY 25:
The app is working on the NOKIA mobile. Also started coding for the "search
application".

DAY 26:
Search program runs successfully on the NetBeans Emulator

DAY 27:
Search Programme runs successfully on mobile phone too.

DAY 28:
Testing the prepared applications on different mobile handsets, the application runs
successfully.

DAY 29:
Started preparing the Project Report for submission in the Media Lab Asia.

DAY 30:
Project Report is ready, submitted the hard copy and soft copy to the Media Lab
Asia. Training Ends.
PROJECT DETAILS

An Overview :
Java Platform, Micro Edition, or Java ME, is a Java platform designed
for embedded systems (mobile devices are one kind of such systems).
Target devices range from industrial controls to mobile
phones (especially feature phones) and set-top boxes. Java ME was
formerly known as Java 2 Platform, Micro Edition (J2ME).
Java ME was designed by Sun Microsystems, acquired by Oracle
Corporation in 2010; the platform replaced a similar
technology, PersonalJava. Originally developed under the Java
Community Process as JSR 68, the different flavors of Java ME have
evolved in separate JSRs. Sun provides areference implementation of
the specification, but has tended not to provide free binary
implementations of its Java ME runtime environment for mobile
devices, rather relying on third parties to provide their own.

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.
Sun Java Platform Micro Edition Software Development Kit 3.0 is
the latest edition. Java ME Platform SDK for Windows is a state-of-the-
art toolbox for developing mobile applications. It integrates CLDC, CDC,
and Blu-ray Disc Java (BD-J) technology into one SDK, and replaces
Java Wireless Toolkit 2.5.2 and Java Toolkit 1.0 for CDC. In other
words the "Java Wireless Toolkit 2.5.2" has once again been
incorporated into the MicroEdition.
Java NetBeans 6.9 :
NetBeans refers to both a platform framework for Java desktop
applications, and an integrated development environment (IDE) for
developing with Java, JavaScript, PHP, Python (no longer supported
after NetBeans 7), Groovy, C, C++, Scala , Clojure , and others. The
NetBeans IDE 7.0 no longer officially supports Ruby and Ruby on Rails,
but a third party plugin allows for development.
The NetBeans IDE is written in Java and can run on Windows, Mac OS,
Linux, Solaris and other platforms supporting a compatible JVM. A pre-
existing JVM or a JDK is not required.
The NetBeans platform allows applications to be developed from a set
of modular software components called modules. Applications based on
the NetBeans platform (including the NetBeans IDE) can be extended
by third party developers.
NetBeans IDE is an open-source integrated development environment.
NetBeans IDE supports development of all Java application types (Java
SE(including JavaFX), Java ME, web, EJB and mobile applications) out
of the box.
Among other features are an Ant-based project system, Maven
support,refactorings,versioncontrol (supporting CVS, Subversion, Merc
urial and Clearcase).
Java Eclipse 3.2 :
Eclipse is a multi-language software development environment
comprising an integrated development environment (IDE) and an
extensible plug-in system. It can be used to develop applications in
Java and by means of various plug-ins, other programming languages
including Ada, C, C++, COBOL, Haskell, Perl, PHP, Python, Ruby
(including Ruby on Rails framework), Scala, Clojure, Groovy and
Scheme. It can also be used to develop packages for the software
Mathematical development environments including the Eclipse Java
Development Tools (JDT) for Java, Eclipse CDT for C/C++ and Eclipse
PDT for PHP, among others.
The initial codebase originated from VisualAge. The Eclipse SDK
(which includes the Java development tools) is meant for Java
developers. Users can extend its abilities by installing plug-ins written
for the Eclipse Platform, such as development toolkits for other
programming languages, and can write and contribute their own plug-in
modules.
Released under the terms of the Eclipse Public License, Eclipse SDK
is free and open source software. It was one of the first IDEs to run
underGNU Classpath and it runs without issues under IcedTea.
MODULE 2 - ( Video Player & Listing Application)

An application able to play video files was coded with the following
codes in J2ME :

Code (for Player Application):


import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class VideoTry2search extends MIDlet implements


CommandListener ,ItemStateListener ,PlayerListener {

public String[] elements ={"1","2"};


public List list =new List(" Select amongst the searched
video files", List.IMPLICIT, elements,null);
public StringItem si,time;
private Gauge gauge = new Gauge("Volume: 50", true, 100,
50);
private VolumeControl volume;
private Form volume1 =new Form("Adjust volume");

public Form form = new Form("VideoPlayer");


private Command Play =new
Command("Play",Command.SCREEN,1);
private Command exitCommand = new Command("Exit",
Command.EXIT, 1);
private Command vol =new
Command("Volume",Command.SCREEN,1);
private Command back =new Command("back",Command.BACK,2);
private Command pause =new
Command("Pause",Command.SCREEN,1);
private Command Resume =new
Command("Resume",Command.SCREEN,1);

private Player player;

public VideoTry2search()
{
list.addCommand(Play);
list.addCommand(exitCommand);
list.setCommandListener(this);
form.addCommand(pause);
form.addCommand(Resume);
form.addCommand(vol);
form.addCommand(back);
form.setCommandListener(this);
volume1.append(gauge);
volume1.addCommand(back);
volume1.setItemStateListener(this);
volume1.setCommandListener(this);

}
public void startApp() {
Display.getDisplay(this).setCurrent(list);
}

public void pauseApp() {


}

public void destroyApp(boolean unconditional) {


}

public void commandAction(Command c, Displayable d) {


if (c == exitCommand)
{
cleanUp();
notifyDestroyed();
return;
}
if (c==Play)
{
String s=list.getString(list.getSelectedIndex());
s="/"+s+".mpg";
si=new StringItem("Playing",s);
playMedia(s);
form.append(si);
}
if(c==vol)
{
Display.getDisplay(this).setCurrent(volume1);
}
if((c==back)&&(d==form))
{
try
{
player.stop();
}
catch (Exception e)
{
}
form.deleteAll();
cleanUp();
Display.getDisplay(this).setCurrent(list);
}
if((c==back)&&(d==volume1))
{
Display.getDisplay(this).setCurrent(form);
}
if(c==pause)
{
try
{
player.stop();
}
catch (Exception e)
{
}
}
if(c==Resume)
{
try {
player.start();
} catch (Exception e) {
}
}
}
public void cleanUp() {
if (player != null) {
player.close();
player = null;
}
}

public void playMedia(String locator)


{
try{
player =
Manager.createPlayer(getClass().getResourceAsStream(locator),
"video/mpeg");
player.realize();
player.addPlayerListener(this);
volume = (VolumeControl)
player.getControl("VolumeControl");
volume.setLevel(70);
gauge.setValue(volume.getLevel());
gauge.setLabel("Volume: " + volume.getLevel());
player.setLoopCount(2);
float t= player.getMediaTime();
String c=String.valueOf(t);
time=new StringItem("Time",c);
form.append(time);
player.start();
}
catch (Exception e) {
e.printStackTrace();
}
}

public void itemStateChanged(Item item) {


volume.setLevel(gauge.getValue());
gauge.setLabel("Volume: " + volume.getLevel());
}

public void playerUpdate(Player player, String event,


Object eventData) {
if(event.equals(PlayerListener.STARTED) ) {
VideoControl vc =
(VideoControl)player.getControl("VideoControl");
Item videoDisp =
(Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null);
form.append(videoDisp);

Display.getDisplay(this).setCurrent(form);
} else if(event.equals(PlayerListener.CLOSED)) {
form.deleteAll();
}
}
}

Code (for Listing Application):

import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class searchplayMidlet extends MIDlet implements


CommandListener,
PlayerListener {
private Display display;
private List itemList;
private Form form;
private Command stop, pause, start;
private Hashtable items, itemsInfo;
private Player player;

public searchplayMidlet() {
display = Display.getDisplay(this);
itemList = new List("Select an item to play",
List.IMPLICIT);
stop = new Command("Stop", Command.STOP, 1);
pause = new Command("Pause", Command.ITEM, 1);
start = new Command("Start", Command.ITEM, 1);
form = new Form("Playing video");
form.addCommand(stop);
form.addCommand(pause);
form.setCommandListener(this);
items = new Hashtable();
itemsInfo = new Hashtable();

items.put("SpringWaterFall...",
"file://SpringWaterFall.mpg");
itemsInfo.put("SpringWaterFall...", "video/mpeg");
items.put("helloboy...", "file://helloboy.mpg");
itemsInfo.put("helloboy...", "video/mpeg");

items.put("pilgrim...", "file://pilgrim.mpg");
itemsInfo.put("pilgrim...", "video/mpeg");

items.put("pirates...", "file://pirates.ogv");
itemsInfo.put("pirates...", "video/ogv");

items.put("pythag1...", "file://pythag1.mp4");
itemsInfo.put("pythag1...", "video/mp4");

items.put("CarelessEnglish...",
"file://CarelessEnglish.mpg");
itemsInfo.put("CarelessEnglish...", "video/mpeg");
}

public void startApp() {


for(Enumeration en = items.keys(); en.hasMoreElements();) {
itemList.append((String)en.nextElement(), null);
}
itemList.setCommandListener(this);
display.setCurrent(itemList);
}

public void pauseApp() {


try {
if(player != null) player.stop();
} catch(Exception e) {}
}

public void destroyApp(boolean unconditional) {


if(player != null) player.close();
}

public void commandAction(Command c, Displayable d){


if(d instanceof List) {
List list = ((List)d);
String key = list.getString(list.getSelectedIndex());
try {
playAudio((String)items.get(key), key);
} catch (Exception e) {
System.err.println("Unable to play: " + e);
e.printStackTrace();
}
} else if(d instanceof Form){
try {
if(c == stop){
player.close();
display.setCurrent(itemList);
form.removeCommand(start);
form.addCommand(pause);
} else if(c == pause){
player.stop();
form.removeCommand(pause);
form.addCommand(start);
} else if(c == start){
player.start();
form.removeCommand(start);
form.addCommand(pause);
}
} catch(Exception e) {
System.err.println(e);
}
}
}

private void playAudio(String locator, String key) throws


Exception {
String file = locator.substring(locator.indexOf("file://")
+ 6,
locator.length());
player =
Manager.createPlayer(getClass().getResourceAsStream(file),
(String)itemsInfo.get(key));
player.addPlayerListener(this);
player.setLoopCount(-1);
player.prefetch();
player.realize();
player.start();
}

public void playerUpdate(Player player, String event,


Object eventData) {
if(event.equals(PlayerListener.STARTED) && new
Long(0L).equals((Long)
eventData)) {
VideoControl vc = null;
if((vc = (VideoControl)player.getControl("VideoControl"))
!= null) {
Item videoDisp =
(Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null);
form.append(videoDisp);
}
display.setCurrent(form);
} else if(event.equals(PlayerListener.CLOSED)) {
form.deleteAll();
}
}
}
MODULE 3 - (Export to Mobile Handset – NOKIA™)

The applications coded were converted into .jar format (Java Archive
file format) and were transferred to the handset via a data cable.

The application was easily installed and ran successfully.

JAR (Java ARchive) is a archive file format typically used to aggregate


many Java class files and associated metadata and resources (text,
images and so on) into one file to distribute application
software or libraries on the Java platform.

The Java™ Archive logo

Application running on NOKIA™ phone


REFERENCES
 Core J2ME Technology & MIDP by John W.Muchow

 J2ME Step-by-Step Tutorial (ibm.com/developerWorks)

USEFUL LINKS

 http://www.oracle.com/technetwork/java/archive-139210.html
 http://uberthings.com/mobile/
 http://ekrishinaip.in/
 http://www.naip.icar.org.in/
 http://www.oracle.com/technetwork/java/javame/javamobile/downl
oad/sdk/index.html to download J2ME SE SDK (Software
Development Kit)

SOFTWARES USED

 Java™ ME Platform SDK 3.0


 Java™ NetBeans 6.9 by Oracle™
 Java™ Eclipse 3.2 SDK Europa
 J2ME Wireless Toolkit 2.2
 Java™ Development Kit 6u20 Windows I586

HARDWARE USED

 Intel™ Core i3 Processor


 2 GB DDRAM
 276 GB hard disk
 762 MB graphic card

You might also like