how can i get information from an exiting contact?
i want to change some information from an exitong contact to xml file(telephone munber,name etc),but i do not know which class should be used in MIP API??
how can i get information from an exiting contact?
i want to change some information from an exitong contact to xml file(telephone munber,name etc),but i do not know which class should be used in MIP API??
You have to use J2ME PIM api for achieving this.
See this:
http://developers.sun.com/techtopics...apis/pim/pim5/
jini
my code like that:
import gov.nist.siplite.header.ContactList;
import java.io.*;
import java.util.Enumeration;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.pim.Contact;
import javax.microedition.pim.PIM;
import javax.microedition.pim.PIMException;
import javax.microedition.pim.PIMList;
import org.kxml.*;
import org.kxml.io.*;
//import org.kxml.wap.*;
public class contactget extends MIDlet implements CommandListener
{
private Display display;
private Command exitCommand,okCommand;
// private TextBox textbox;
private Alert alert;
public String tagTable[] = {
"id",
"firstname",
"mun"
};
public contactget(){
display = Display.getDisplay( this );
//textbox=new TextBox("xmltex","",5000,0);
alert=new Alert("alert","Are you start xml form contact?",null,AlertType.INFO);
exitCommand = new Command( "Exit", Command.EXIT, 1 );
okCommand=new Command("statxml",Command.OK,1);
// textbox.addCommand(exitCommand);
// textbox.addCommand(okCommand);
// textbox.setCommandListener(this);
alert.addCommand(exitCommand);
alert.addCommand(okCommand);
alert.setCommandListener(this);
}
public void commandAction( Command c, Displayable d ){
if( c == exitCommand )
{
destroyApp( false);
notifyDestroyed();
}else if(c==okCommand)
{
try
{
testXML();
}catch( Exception e )
{
System.err.println( "Exception " + e );
}
}
}
protected void destroyApp( boolean unconditional )
{
}
protected void pauseApp()
{
}
protected void startApp()
{
display.setCurrent(alert);
}
private void log( String str )
{
System.out.println( str );
}
private void testXML() throws IOException {
log( "Writing compressed XML to a string..." );
ByteArrayOutputStream out = new ByteArrayOutputStream();
XmlWriter xw = new XmlWriter( new OutputStreamWriter( out ) );
AbstractXmlWriter writer=( AbstractXmlWriter )xw;
PIM pim = PIM.getInstance();
ContactList list = null;
try {
list = (ContactList)pim.openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
// do something with the contact list
}catch(PIMException pe){
pe.printStackTrace();
}catch(SecurityException se){
se.printStackTrace();
}
log("list = (ContactList)pim.openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);");
try {
Enumeration items = ((PIMList) list).items();
while(items.hasMoreElements()) {
Contact contact = (Contact)items.nextElement();
writer.startTag("id");
writer.startTag( "firstname" );
int field=contact.NAME ;
int index=contact.getPreferredIndex( field) ;
String temp=contact.getString(field, index);
writer.write( temp );
writer.endTag();
writer.startTag( "mun" );
int field2=contact.TEL;
int index2=contact.getPreferredIndex( field) ;
String temp2=contact.getString(field2, index2);
writer.write( temp2);
writer.endTag();
writer.endTag();
writer.close();
}
}catch(PIMException pe) {
pe.printStackTrace();
}catch(SecurityException se) {
se.printStackTrace();
}
String str = new String( out.toByteArray() );
log( "String length is " + str.length() );
log( "String value is" );
log( str );
log( "Writing compressed XML to a string..." );
out = new ByteArrayOutputStream();
}
}
but i can not get the contact information ?
why ??