Will Perone

To set up contacts for the WTK or Sprint emulator for JSR75 access you need to make some vcards. The vcards should have the following format:
begin:vcard
fn:Will Perone
n:Perone; Will;; 
TEL;HOME;VOICE:123-456-7890
TEL;CELL;VOICE:987-654-3210
URL;HOME:http://willperone.net
EMAIL;INTERNET:webmaster@willperone.net
version:2.1
end:vcard
The TEL, UTL and EMAIL lines are all optional (and I think the n and fn too). You can go here to find out more about the vcard format.
The cards should be saved in .vcf files (If you have Outlook or Outlook Express you can create contacts in there and save them as vcard files as well). Put the vcards in the (toolkit)/appdb/(phone)/pim/contacts/Contacts and that's it! Now your j2me app will be able to access some contacts in the emulator.

The following is an example of how query the actual JSR75 contacts from the phone.
import java.util.Enumeration;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;


public boolean getPhoneContacts() {
	ContactList contacts = null;
	try {
		contacts = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
		if (!contacts.isSupportedField(Contact.TEL)) {            
			return false;
		}

		Enumeration contactEnum = contacts.items();

		while (contactEnum.hasMoreElements()) {
			Contact c = (Contact) contactEnum.nextElement();

			// see how many phone numbers are attached to the contact
			int telCount = c.countValues(Contact.TEL);
			if (telCount==0) continue; // no phone numbers for this contact
			long     currPhoneNum;
			long[]   phoneNums;
						
			for (int i = 0; i < telCount; i++) {
				// validiate the phone number
				String tel = c.getString(Contact.TEL, i);
				if (tel.length() > 0) {
					currPhoneNum = Long.parseLong(tel);  
					if (currPhoneNum != YourPhoneNumber) {
						// add this currPhoneNum to this contact's list of phone numbers
						long[] phoneNumsBackup= phoneNums;
						phoneNums = new long[phoneNumsBackup.length+1];
						System.arraycopy(phoneNumsBackup, 0, phoneNums, 0, phoneNumsBackup.length);
						phoneNums[phoneNums.length-1] = currPhoneNum;
					}
				}
			}

			// now try to fetch any semblance of a name we can get
			String[] contactName;
			StringBuffer nameStrBuffer;
			String name= null;
			try {
				if (contacts.isSupportedField(Contact.FORMATTED_NAME) && c.countValues(Contact.FORMATTED_NAME) > 0) {
					name = c.getString(Contact.FORMATTED_NAME, 0);
				} else if ((contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN) ||
							contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY))
							&& c.countValues(Contact.NAME) > 0) {
					contactName= c.getStringArray(Contact.NAME, 0);
					if (contactName != null) {
						nameStrBuffer = new StringBuffer();
						if (contactName[Contact.NAME_GIVEN] != null && contactName[Contact.NAME_GIVEN].trim().length() > 0) {
							nameStrBuffer.append(contactName[Contact.NAME_GIVEN]);
						}
						if (contactName[Contact.NAME_FAMILY] != null && contactName[Contact.NAME_FAMILY].trim().length() > 0) {
							if (nameStrBuffer.length() > 0) nameStrBuffer.append(' ');
							nameStrBuffer.append(contactName[Contact.NAME_FAMILY]);
						}
						if (nameStrBuffer.length() > 0) {                                    
							name = nameStrBuffer.toString();
						} else {                                    
							// handle the name field is blank
						}
					}
				} else { 
					// handle no name field supported                    
				}
			} catch (Exception e) {
				// handle an index out of bound, illegalArugment or unsupportedField exception								
			}

			// add this contact to the your contact list			
			// the contact is stored in 'name' and 'phoneNums'
		}

	} catch (Exception e) {		
		return false;
	}
	return true;
}
For more info on programming JSR75/PIM, go here.

3 Comments
yhobzzflby 0 0
Hello! Good Site! Thanks you!
Wilians 2012/09/10 Contact Me0 0
I don't know who you wrote this for but you heelpd a brother out.
Ирина Викторовна 2016/07/21 Contact Me0 0

<- for private contact