New User?   Join Now     Login            Forgot Password?    
Browse by Category
Articles
Games
Algorithms
Software
Browse Projects
XamlQuery v1.2
YtoX
Racketbot
Browse Topics
J2ME Contact Management  (11560 hits)
 Share this Article
 
Posted by Prabu Arumugam on Apr-23-2010
Languages: Java, J2ME

About this Application

We present a simple contact management application for Java enabled mobile phones. This article will be a great resource for novice J2ME programmers. This is a complete working application and full source code can be downloaded below. However, this is not an alternative to default "Contacts" application available in all mobile phones.

Contact Entity

The source code contains three files, namely Contact.java, ContactsDatabase.java and ContactsInfo.java.

The following is the data structure used to store details of a contact/person.

	public class Contact
	{
		public String FirstName;
		public String LastName;
		public String MobileNumber;
		public String HomeNumber;
		public String OfficeNumber;
		public String FaxNumber;
		public String OtherNumber;
		public String EMail;
	}

Contacts Database

ContactsDatabase class takes care of all persistent storage activities related to the contact list.

Persistent storage in MIDP is centered around record stores. A record store is a small database file that contains pieces of data called records. J2ME contains RecordStore class for managing individual records as well as entire record stores. We use the inbuilt methods of this class for all datastore and record level operations.

A record is simply an array of bytes. So, we have to write own utility functions to convert our Contact data-structure to and from a byte-array. The following function converts a byte array into a Contact object. This function is used while reading contacts from the record-store.

	private Contact deserialize(byte[] recordBytes)
	{
		//split the byte-array into strings
		Vector recordValues = new Vector();
		
		int startIndex = 0;
		int endIndex = -1;
		for(int i = 0; i < recordBytes.length; i++)
		{
			if(recordBytes[i] == ':')
			{
				endIndex = i - 1;
				recordValues.addElement(new String(recordBytes, startIndex, endIndex - startIndex + 1));
				startIndex = i + 1;
			}
		}

		//build contact-object
		Contact contact = new Contact();
		contact.FirstName = (String)recordValues.elementAt(0);
		contact.LastName = (String)recordValues.elementAt(1);
		contact.MobileNumber = (String)recordValues.elementAt(2);
		contact.HomeNumber = (String)recordValues.elementAt(3);
		contact.OfficeNumber = (String)recordValues.elementAt(4);
		contact.FaxNumber = (String)recordValues.elementAt(5);
		contact.OtherNumber = (String)recordValues.elementAt(6);
		contact.EMail = (String)recordValues.elementAt(7);
		return(contact);
	}

The following function converts a Contact object into a byte array. This function is used while adding new contact and updating details of existing contacts.

	private byte[] serialize(Contact contact)
	{
		String recordValue = "";
		recordValue += contact.FirstName + ":";
		recordValue += contact.LastName + ":";
		recordValue += contact.MobileNumber + ":";
		recordValue += contact.HomeNumber + ":";
		recordValue += contact.OfficeNumber + ":";
		recordValue += contact.FaxNumber + ":";
		recordValue += contact.OtherNumber + ":";
		recordValue += contact.EMail + ":";
		return(recordValue.getBytes());
	}

ContactsInfo Application

ContactsInfo class is the main J2ME application class, containing all the GUI related stuff. The entire application is built with these controls: List, Form and TextField. The first and main screen of the application displays the list of contacts saved by the user. The user can invoke a menu containing the options to add new contact, to edit an existing contact, to delete an existing contact and to view details of an existing contact. The following is the screenshot in J2ME simulator.

This class will be very helpful for understanding a basic MIDlet life cycle, using Display class to switch between various forms in the application, event handling with commands for responding to user actions, getting user input in forms and showing alert & confirmation messages.

The application is developed with J2SDK 1.4.2 build 19 and J2ME Wireless Toolkit 2.2; the application will be compatible with all Java enabled mobile phones and future MIDlet versions.


 Downloads for this article
File Language Tools
ContactsInfo-J2ME-Source  3.61 kb  (369 downloads) J2ME J2ME WTK 2.2

 Share this Article

 Comments on this Article
Comment by supriya on Sep-26-2013
thanks..
Comment by anhlavodoinb1 on Aug-16-2013
good
Comment by Chirag on Aug-06-2013
Thank you very.........
Comment by Sudha Patil on Mar-22-2013
Hello..I am not able to register can you please send me the file "ContactsInfo-J2ME-Source.zip" to my mail Id : sppatil095@gmail.com. Thank you
Comment by Rals on Oct-31-2012
Hi....!!!!!!!I am trying to register but i can't. Please would you mind plz send me the file "ContactsIfo - J2ME - Source.zip" to my email? My e-mail is kshirsagarrahul91@gmail.com
Comment by sunnysing93 on Mar-02-2012
Thanks a lot ....I am very very happy to get this coding. It helps me a lot for my on going project.....
Comment by oromis on Mar-01-2012
thanks....
Comment by saravanakumar.s on Feb-20-2012
hi,your site was very use ful for j2me devolopers.I am trying to register but can't.please send me the file "ContactsIfo - J2ME - Source.zip"to my mail sayasayasaya90@gmail.com
Comment by sona on Sep-21-2011
hi i really need the code , kindly mail the zipped file to me on sonalisharma129@gmail.com
Comment by Nikhil on Aug-11-2011
hi..i am trying to register but it fails..can u send me ."ContactsInfo-J2ME-Source.zip" file at my email address nikhilnavlakha@gmail.com. thanks....
Comment by Maxzener on Jul-13-2011
Hi! Your site is very helpful for developers. I am trying to register but i can't. Please would you mind sending me the file "ContactsIfo - J2ME - Source.zip" to my email? My e-mail is max...@hotmail.com . Thanks a lot.
Comment by narendra on Nov-30-2010
thanks ,,,
Comment by rajesh on Aug-09-2010
Your site very very useful for all developers. Thanks to your work.
Comment by Sunil on Jun-07-2010
hi, can you please send me the code for reading and writting the contact in a sony ericsson phone.. to this mail id : sunillinus05@gmail.com With Regards Sunil
 Post your comment here
Your Name
Your Email
Comment
Post Comment

About About      Terms Terms      Contact Contact
codeding on Facebook Facebook      codeding on Twitter Twitter