Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 12:42, 13 December 2007.

How to read contacts using JSR 75

From Forum Nokia Wiki

This Midlet reads the contact names and numbers from the Phonebook using JSR 75

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
 
public class   PIMMidelt extends MIDlet 
{
	ReadPIM readPim;
	Display display;
 
	public void startApp()
	{
		display = Display.getDisplay(this);
		readPim  = new ReadPIM(this);
		display.setCurrent(readPim);
	}
	public void pauseApp()
	{
	}
	public void destroyApp(boolean uc)
	{
	}
}
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
import java.util.*;
import java.io.*;
public class ReadPIM extends Form  implements Runnable,CommandListener
{
	PIM pim;
	PIMList pimlist;
	Contact contact=null;
	Enumeration enumeration;
	PIMMidelt midlet;
 
	String contactName="";
	String contactNo="";
	
	
	StringItem name;
	StringItem telno;
	Thread thread=null;
	Command exitCmd = new Command("Exit",Command.EXIT,1);
 
	public ReadPIM(PIMMidelt midlet)
	{
		super("Reading contacts");
		this.midlet = midlet;
 
		pim = PIM.getInstance();
		
		thread = new  Thread(this);
		thread.start();
		addCommand(exitCmd);
		setCommandListener(this);
	
	}
 
	public void run()
	{
		readContacts();
	}
 
	public void	readContacts()
	{
		String[] lists = pim.listPIMLists(pim.CONTACT_LIST);
		for (int i = 0; i < lists.length; i++)
		{
		try{
		pimlist = pim.openPIMList(pim.CONTACT_LIST,pim.READ_WRITE);
		}catch(Exception e){}
		
 
		try{
		enumeration = pimlist.items();
		}catch(Exception e){}
 
		while (enumeration.hasMoreElements())
		{
		 contact	=	(Contact)enumeration.nextElement();
 
		 try{
			if(pimlist.isSupportedField(Contact.FORMATTED_NAME)&& (contact.countValues(Contact.FORMATTED_NAME) >0))
			 {
				contactName += contact.getString(Contact.FORMATTED_NAME,0)  +"\r\n";;
				 System.out.println("COntact name:"+contactName);
			 }
		}catch( Exception e){}
 
		int phoneNos = contact.countValues(Contact.TEL);
		try{
			if(pimlist.isSupportedField(Contact.TEL) &&(contact.countValues(Contact.TEL) >0))
			contactNo += contact.getString(contact.TEL,0) +"\r\n";
			 System.out.println("contact No  :"+contactNo);
			}catch( Exception e){}
 
		}
		
		name = new StringItem("Name",contactName);
		telno = new StringItem("No",contactNo);
		append(name);
		append(telno);
 
		}
	}
 
	public void commandAction(Command c , Displayable d)
	{
		if(c == exitCmd)
		{
			midlet.destroyApp(true);
			midlet.notifyDestroyed();
 
		}
 
	}
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
hw to read GPS data from built-in receiver ??? viku_006 Mobile Java Networking & Messaging & Security 4 2007-10-25 09:05
can we take contacts.cdb backup. iaj General Symbian C++ 4 2006-06-29 12:54
jsr-205 and J2ME?? smaatta Mobile Java General 5 2005-07-13 13:00
Give us JSR 253 - Mobile Telephony API barryj Tools and SDK Feedback 7 2008-01-14 17:05
Contacts Plugin on S60 3rd edition alexey_gusev Symbian User Interface 1 2007-05-14 12:11
 
Powered by MediaWiki