Here is the code
It just create a new contact in the AddressBook
and i use Nokia 7360 for running my application
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
import java.util.Enumeration;
public class AddContact extends MIDlet implements CommandListener,Runnable
{
Form form;
Display display;
Command exit;
Command add;
Alert alert;
public Thread th;
private boolean quit = false;
public AddContact()
{
display = Display.getDisplay(this);
form = new Form("Add Contact");
exit = new Command("Exit",Command.EXIT,1);
add = new Command("Add Contact",Command.OK,1);
alert = new Alert("Add Contact","Contact Added Succesfully",null,null);
alert.setTimeout(Alert.FOREVER);
form.addCommand(add);
form.addCommand(exit);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
th = new Thread(this);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable d) {
if(c==exit)
{
destroyApp(false);
notifyDestroyed();
}
else if (c == add)
{
if(!quit)
{
th.start();
display.setCurrent(alert);
}
}
}
public void quit()
{
quit = true;
}
public void run()
{
while (!quit)
{
try
{
PIM pim = PIM.getInstance();
ContactList cl = null;
Contact new_contact = null;
Enumeration read_contact = null;
String final_no="";
try
{
cl = (ContactList)pim.openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);
}
catch(PIMException pime)
{
Alert alert_1 = new Alert("Error","Error Accessing Database"+pime,null,null);
alert_1.setTimeout(Alert.FOREVER);
alert_1.setType(AlertType.ERROR);
display.setCurrent(alert_1);
}
catch(SecurityException se)
{
Alert alert_2 = new Alert("Error","Security Error"+se,null,null);
alert_2.setTimeout(Alert.FOREVER);
alert_2.setType(AlertType.ERROR);
display.setCurrent(alert_2);
}
new_contact = cl.createContact();
new_contact.addString(Contact.TEL,Contact.ATTR_HOME,"123456");
new_contact.addString(Contact.FORMATTED_NAME,Contact.ATTR_NONE,"AasdD");
new_contact.addString(Contact.TEL,Contact.ATTR_MOBILE,"2634465");
new_contact.addString(Contact.TEL,Contact.ATTR_FAX,"+91 7834465");
new_contact.addString(Contact.TEL,Contact.ATTR_PAGER,"7034465");
new_contact.addString(Contact.TEL,Contact.ATTR_MOBILE,"9234465");
try
{
new_contact.commit();
}
catch(PIMException piem)
{
Alert alert_4 = new Alert("Error","Error while saving Data"+piem,null,null);
alert_4.setTimeout(Alert.FOREVER);
alert_4.setType(AlertType.ERROR);
display.setCurrent(alert_4);
}
try
{
cl.close();
}
catch(PIMException piem)
{
Alert alert_5 = new Alert("Error","Error Closing Application"+piem,null,null);
alert_5.setTimeout(Alert.FOREVER);
alert_5.setType(AlertType.ERROR);
display.setCurrent(alert_5);
}
}
catch (Exception e)
{
Alert alert_4 = new Alert("Error","Error on first try"+e,null,null);
alert_4.setTimeout(Alert.FOREVER);
alert_4.setType(AlertType.ERROR);
display.setCurrent(alert_4);
}
quit();
}
}
}
HI ,
I set all permission,but i can not able to add and edit .
i also check the midlet access option and i set it to add edit user data
So that it allows me to add and edit data.
but my problem is because of
http://forum.nokia.com/Technical_Library/FNTL/General_phone_number_cannot_be_accessed_by_using_PIM_API_JSR-75.htm
I am testing on Nokia 7360...which contains General numbers...
so that i can not able to use
countValues(Contact.TEL) to count total TEL numbers
because it gives error due to the bug i mention earlier......
and i also want to know about signing midlet...
i just know about Sign Midlet Option in WTK emulator.
Can i sign midlet from WTK emulator or is there anything i have to do from my mobile..
regards
Pravin