Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
meenu
Posts: 15
Registered: ‎09-08-2009
My Device: Not Specified

open native address book

can i get a code how to open native address from Textfield(ADD A CONTACT FROM ADDRESS BOOK)?
Please use plain text.
Developer
Shraddha
Posts: 34
Registered: ‎07-25-2008
My Device: Not Specified

Re: open native address book

I am not very sure what you need, but you may check the AddressInfo class
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: open native address book

This KB Article will help you

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800363/How_To_...

 

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800363/How_To_...

 

 


Press the kudos button to thank the user who helped you.

If your problem was get solved then please mark the thread as "Accepted solution".

 

 

 

Deepesh Gupta
Please use plain text.
New Developer
meenu
Posts: 15
Registered: ‎09-08-2009
My Device: Not Specified

Re: open native address book

Hii..ThanksI used ur code in my app but it displays nothing..import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.system.*;import net.rim.device.api.ui.MenuItem;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.component.BasicEditField;import net.rim.device.api.ui.component.PasswordEditField;import net.rim.device.api.ui.component.ButtonField;import net.rim.device.api.ui.component.Dialog;import net.rim.device.api.ui.component.LabelField;import net.rim.device.api.ui.component.Menu;import net.rim.device.api.ui.component.SeparatorField;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.FieldChangeListener;import net.rim.device.api.ui.Field;import net.rim.device.api.ui.component.ObjectListField;import net.rim.blackberry.api.menuitem.ApplicationMenuIte mRepository;import net.rim.device.api.system.Application;import net.rim.blackberry.api.*;import javax.microedition.pim.Contact;import javax.microedition.pim.ContactList;import javax.microedition.pim.PIM;import javax.microedition.pim.PIMException;import javax.microedition.pim.PIMItem;import java.util.Enumeration;import net.rim.blackberry.api.pdap.*;import net.rim.blackberry.api.pim.BlackBerryContactList;import net.rim.blackberry.api.pim.BlackBerryContact;public class SendSms extends UiApplication {public static void main(String argv[]) {SendSms app = new SendSms();app.enterEventDispatcher();}public SendSms() {pushScreen(new HelloScreen());}}final class HelloScreen extends MainScreen {private LogOff _logoff;public HelloScreen() {super();LabelField title = new LabelField ("BlackBerry App", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);setTitle(title);final ObjectListField list = new ObjectListField();String[] items = new String[] { "Call To One", "Call To group" };list.set(items);add(list);}private MenuItem _logoffMenu = new MenuItem("Select", 110, 10) {public void run() {LogOff _logoff = new LogOff();UiApplication.getUiApplication().pushScreen(_logof f);}};private MenuItem _closeItemMenu = new MenuItem("Exit", 200000, 10) {public void run() {onClose();}};protected void makeMenu( Menu menu, int instance ) {menu.add(_logoffMenu);menu.add(_closeItemMenu);}static class LogOff extends MainScreen {private Contact cscr;public LogOff() {super();BlackBerryContact contact = null;LabelField title = new LabelField("Send Message", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);setTitle(title);String Name = "";LabelField message;String result = "OK";if (result.equals("OK")) {message = new LabelField("Enter Your Mobile Number");}else {message = new LabelField("Log off failed, please try again");}add(message);}private MenuItem _logoffMenu = new MenuItem("Select Contact", 110, 10) {public void run() {Contact cscr = new Contact();UiApplication.getUiApplication().pushScreen(cscr);}};private MenuItem _backItemMenu = new MenuItem("Back", 200000, 10) {public void run() {}};protected void makeMenu( Menu menu, int instance ) {menu.add(_logoffMenu);menu.add(_backItemMenu);}static class Contact extends MainScreen {public String getPimList() {BlackBerryContact contact = null;String contactnames = null;try {BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM .READ_WRITE);contact = (BlackBerryContact) list.choose(null,BlackBerryContactList.AddressType s.EMAIL,false);System.out.println("contact"+contact);} catch (Exception e) {} int numValues = 0;try {numValues = contact.countValues(BlackBerryContact.TEL);contactnames = new String();} catch (Exception e) {}for (int i = 0; i < numValues; i++) {if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK) {contactnames = contact.getString(BlackBerryContact.TEL, i);System.out.println("contactnames"+contactnames);} }return contactnames;}} }public boolean onClose() {Dialog.alert("Visit Again!");System.exit(0);return true;}} can u plz tell what a problem with this code..why its displays nothing when i click on select contact menuitem..
Please use plain text.
New Developer
meenu
Posts: 15
Registered: ‎09-08-2009
My Device: Not Specified

Re: open native address book

[ Edited ]

Hii..ThanksI used ur code in my app but it displays nothing..

Hii..Thanks
I used ur code in my app but it displays nothing..
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.ObjectListField;
import net.rim.blackberry.api.menuitem.ApplicationMenuIte mRepository;
import net.rim.device.api.system.Application;
import net.rim.blackberry.api.*;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;
import javax.microedition.pim.PIMException;
import javax.microedition.pim.PIMItem;
import java.util.Enumeration;
import net.rim.blackberry.api.pdap.*;
import net.rim.blackberry.api.pim.BlackBerryContactList;
import net.rim.blackberry.api.pim.BlackBerryContact;



public class SendSms extends UiApplication {
public static void main(String argv[]) {
SendSms app = new SendSms();
app.enterEventDispatcher();


}

public SendSms() {
pushScreen(new HelloScreen());
}

}
final class HelloScreen extends MainScreen {
private LogOff _logoff;

public HelloScreen() {
super();
LabelField title = new LabelField ("BlackBerry App", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
final ObjectListField list = new ObjectListField();
String[] items = new String[] { "Call To One", "Call To group" };
list.set(items);
add(list);

}

private MenuItem _logoffMenu = new MenuItem("Select", 110, 10) {
public void run() {
LogOff _logoff = new LogOff();
UiApplication.getUiApplication().pushScreen(_logof f);
}
};

private MenuItem _closeItemMenu = new MenuItem("Exit", 200000, 10) {
public void run() {
onClose();
}
};

protected void makeMenu( Menu menu, int instance ) {
menu.add(_logoffMenu);
menu.add(_closeItemMenu);
}

static class LogOff extends MainScreen {
private Contact cscr;
public LogOff() {
super();

BlackBerryContact contact = null;
LabelField title = new LabelField("Send Message", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
String Name = "";
LabelField message;
String result = "OK";
if (result.equals("OK")) {
message = new LabelField("Enter Your Mobile Number");
}
else {
message = new LabelField("Log off failed, please try again");
}
add(message);
}
private MenuItem _logoffMenu = new MenuItem("Select Contact", 110, 10) {
public void run() {
Contact cscr = new Contact();
UiApplication.getUiApplication().pushScreen(cscr);

}
};
private MenuItem _backItemMenu = new MenuItem("Back", 200000, 10) {
public void run() {

}
};

protected void makeMenu( Menu menu, int instance ) {
menu.add(_logoffMenu);
menu.add(_backItemMenu);
}
static class Contact extends MainScreen {
public String getPimList() {
BlackBerryContact contact = null;
String contactnames = null;
try {
BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM .READ_WRITE);
contact = (BlackBerryContact) list.choose(null,BlackBerryContactList.AddressType s.EMAIL,false);
System.out.println("contact"+contact);
} catch (Exception e) {

int numValues = 0;
try {
numValues = contact.countValues(BlackBerryContact.TEL);
contactnames = new String();
} catch (Exception e) {
}
for (int i = 0; i < numValues; i++) {
if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK) {
contactnames = contact.getString(BlackBerryContact.TEL, i);
System.out.println("contactnames"+contactnames);

}
return contactnames;
}



}



public boolean onClose() {
Dialog.alert("Visit Again!");
System.exit(0);
return true;
}


can u plz tell what a problem with this code..why its displays nothing when i click on select contact menuitem..

 

 

Message Edited by meenu on 09-15-2009 07:59 AM
Message Edited by meenu on 09-15-2009 08:00 AM
Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: open native address book

Are you testing it on Simulator? Have you added contact detsils to the Contacts of Simulator?

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
New Developer
meenu
Posts: 15
Registered: ‎09-08-2009
My Device: Not Specified

Re: open native address book

yes i tested it on simulator and there is contacts in the native addressbook.
Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: open native address book

What is happening when you run the code provided by KB article, mentioned by Deepesh?

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800363/How_To_...


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
New Developer
meenu
Posts: 15
Registered: ‎09-08-2009
My Device: Not Specified

Re: open native address book

My motive is only select the phonennumber from the native address book not editing,adding...etc.so using 1 link(how to launch address book given by Deepesh)...but as i cheked the flow it doesn't go after this line in code

  BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);

 

import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.system.*;import net.rim.device.api.ui.MenuItem;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.component.BasicEditField;import net.rim.device.api.ui.component.PasswordEditField;import net.rim.device.api.ui.component.ButtonField;import net.rim.device.api.ui.component.Dialog;import net.rim.device.api.ui.component.LabelField;import net.rim.device.api.ui.component.Menu;import net.rim.device.api.ui.component.SeparatorField;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.FieldChangeListener;import net.rim.device.api.ui.Field;import net.rim.device.api.ui.component.ObjectListField;import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;import net.rim.device.api.system.Application;import net.rim.blackberry.api.*;import javax.microedition.pim.Contact;import javax.microedition.pim.ContactList;import javax.microedition.pim.PIM;import javax.microedition.pim.PIMException;import javax.microedition.pim.PIMItem;import java.util.Enumeration;import net.rim.blackberry.api.pdap.*;import net.rim.blackberry.api.pim.BlackBerryContactList;import net.rim.blackberry.api.pim.BlackBerryContact;public class SendSms extends UiApplication { public static void main(String argv[]) { SendSms app = new SendSms(); app.enterEventDispatcher(); } public SendSms() { pushScreen(new HelloScreen()); }} final class HelloScreen extends MainScreen { private LogOff _logoff; public HelloScreen() { super(); LabelField title = new LabelField ("BlackBerry App", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); final ObjectListField list = new ObjectListField(); String[] items = new String[] { "Call To One", "Call To group" }; list.set(items); add(list); } private MenuItem _logoffMenu = new MenuItem("Select", 110, 10) { public void run() { LogOff _logoff = new LogOff(); UiApplication.getUiApplication().pushScreen(_logoff); } }; private MenuItem _closeItemMenu = new MenuItem("Exit", 200000, 10) { public void run() { onClose(); } }; protected void makeMenu( Menu menu, int instance ) { menu.add(_logoffMenu); menu.add(_closeItemMenu); } static class LogOff extends MainScreen { public LogOff() { super(); EditField edit; BlackBerryContact contact = null; edit = new EditField("EditField: ", "", 10, EditField.FILTER_DEFAULT); LabelField title = new LabelField("Send Message", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); String Name = ""; String result = "OK"; if (result.equals("OK")) { // message = new LabelField("Enter Your Mobile Number"); edit = new EditField("EditField: ", "", 10, EditField.FILTER_PHONE); } else { // edit = new EditField("Log off failed, please try again"); } // add(edit); } private MenuItem _logoffMenu = new MenuItem("Select Contact", 110, 10) { public void run() { HelloScreen hello = new HelloScreen(); String contanctName = hello.getPimList(); System.out.println("contanctName"+contanctName); } }; private MenuItem _backItemMenu = new MenuItem("Back", 200000, 10) { public void run() { } }; protected void makeMenu( Menu menu, int instance ) { menu.add(_logoffMenu); menu.add(_backItemMenu); } } public String getPimList() { BlackBerryContact contact = null; String contactnames = null;try { BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE); System.out.println("********************"); contact = (BlackBerryContact) list.choose(null,BlackBerryContactList.AddressTypes.EMAIL,true); System.out.println("***********11111111111*********");} catch (Exception e) {}int numValues = 0;try {numValues = contact.countValues(BlackBerryContact.TEL);contactnames = new String();} catch (Exception e) {}for (int i = 0; i < numValues; i++) {if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK) {contactnames = contact.getString(BlackBerryContact.TEL, i);System.out.println("contactnames"+contactnames);} }return contactnames;} public boolean onClose() { Dialog.alert("Visit Again!"); System.exit(0); return true; } }

 

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: open native address book

The example which is listed above doesn't list the contacts?

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.