×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    how can i get information from an exiting contact?

    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??

  2. #2
    Regular Contributor
    Join Date
    Jan 2006
    Posts
    90

    Re: how can i get information from an exiting contact?

    You have to use J2ME PIM api for achieving this.
    See this:
    http://developers.sun.com/techtopics...apis/pim/pim5/

    jini

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: how can i get information from an exiting contact?

    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 ??

Similar Threads

  1. Prototype SDK 2.0 setup problem
    By jackmcardle in forum Mobile Java Tools & SDKs
    Replies: 4
    Last Post: 2007-01-09, 16:21
  2. Contact information on S40 3rd Edition
    By lpinguin in forum Mobile Java General
    Replies: 1
    Last Post: 2006-10-19, 23:44
  3. Replies: 0
    Last Post: 2004-12-01, 16:59
  4. Sending Contact information from PC to 9210
    By cl_eci_dev in forum Symbian
    Replies: 2
    Last Post: 2002-05-14, 03:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×