open native address book
How to open native address book from java app of blackberry phone and select a phone number in textfield?
|
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(); } 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); } } return contactnames; } |
Quote:
Thanks alot but in JDE 4.2.0 it gives an error:- choose(net.rim.blackberry.api.pim.Contact,int,bool ean) in net.rim.blackberry.api.pim.BlackBerryContactList cannot be applied to () contact = (BlackBerryContact) list.choose(); Plz reply soon.. |
choose() api is not valid for JDE 4.2, it was added in JDE 4.2.1.
you can use choose(Contact previous, int type, boolean allowCrossService) instead of choose() api with correct parameters. |
Quote:
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.. |
there is no need to create a another class
private MenuItem _logoffMenu = new MenuItem("Select Contact", 110, 10) { public void run() { String contanctName = getPimList(); } }; 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; } and use this contactName for your purpose. |
Quote:
BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM .READ_WRITE); |
Quote:
if it is then a contact will be selectable only if it has Email entry... just check whether the contact u r trying to select has Email entry or not... |
Quote:
Now i installed JDE 4.3 for running choose() method..In JDE 4.3 API reference i checked this method is defined but it gives error choose(net.rim.blackberry.api.pim.Contact,int,bool ean) in net.rim.blackberry.api.pim.BlackBerryContactList cannot be applied to () contact = list.choose(); Plz help me why its happening.. |
It should work on JDE 4.3, just check the version u r using for compiling the code... u must be using an older version to compile the code...
compile ur code by using jde 4.3 and then try to run it... |
Quote:
that is already compiled in 4.3.1...so i can rechecked where is the problem.. |
there must something u r doing in wrong manner... i've tried the same thing and it is working correctly on my end...
following are the code snippets i've used for JDE 4.3 Code:
BlackBerryContactList contacts = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE); Code:
BlackBerryContactList contacts = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE); |
Quote:
Thanks alot...its worked out. Now i am able to open address book. There is one more question in menu of Blackberry native address book can i append the name of my application and invoke my application from the native address book...Is it possible?If yes then How? |
Quote:
This is class which append the menu in native address book. Code:
package device.pim; Code:
/* |
use this run() method
public Object run(Object context) { if (context == null) { return null; } if (!(context instanceof BlackBerryContact)) { return null; } BlackBerryContact c = (BlackBerryContact)context; if (c != null) { int numValues = 0; String contactnames = new String();; try { numValues = c.countValues(BlackBerryContact.TEL); contactnames = new String(); } catch (Exception e) { } for (int i = 0; i < numValues; i++) { if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK) { contactnames = c.getString(BlackBerryContact.TEL, i); } else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME) { contactnames = c.getString(BlackBerryContact.TEL, i); } else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) { contactnames = c.getString(BlackBerryContact.TEL, i); } else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_OTHER) { contactnames = c.getString(BlackBerryContact.TEL, i); } } reciever = contactnames; Application.getApplication().requestForeground(); // on invocation, will call the main method of this app. with // argument as specified in addMenuItem } else { throw new IllegalStateException( "Context is null, expected a textmessage instance" + context.toString()); } return null; } |
Can someone please give me the code to implement this ?
I tried it on my own but I only get a blank screen when I try to select a contact |
All times are GMT -5. The time now is 12:47 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.