BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   open native address book (http://www.blackberryforums.com/showthread.php?t=204145)

sonia1986 09-14-2009 06:52 AM

open native address book
 
How to open native address book from java app of blackberry phone and select a phone number in textfield?

vivartpandey 09-14-2009 08:09 AM

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;
}

sonia1986 09-15-2009 03:06 AM

Quote:

Originally Posted by vivartpandey (Post 1470949)
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;
}

Hello
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..

pgoeol 09-15-2009 04:01 AM

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.

sonia1986 09-15-2009 06:53 AM

Quote:

Originally Posted by pgoeol (Post 1471565)
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.

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

vivartpandey 09-15-2009 07:25 AM

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.

sonia1986 09-15-2009 08:14 AM

Quote:

Originally Posted by vivartpandey (Post 1471631)
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.

thanks...but still facing the same problem.As i checked the flow it doesn't go after this line...
BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM .READ_WRITE);

pgoeol 09-15-2009 10:43 AM

Quote:

Originally Posted by sonia1986 (Post 1471662)
thanks...but still facing the same problem.As i checked the flow it doesn't go after this line...
BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM .READ_WRITE);

does it open address book on the phone???
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...

sonia1986 09-16-2009 04:29 AM

Quote:

Originally Posted by pgoeol (Post 1471749)
does it open address book on the phone???
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...

on phone i have to signed the application so i using it on simulator..
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..

pgoeol 09-16-2009 05:37 AM

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

sonia1986 09-16-2009 07:55 AM

Quote:

Originally Posted by pgoeol (Post 1472206)
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...

No i am compile it in 4.3.1...can u plz send some example related to this
that is already compiled in 4.3.1...so i can rechecked where is the problem..

pgoeol 09-16-2009 09:18 AM

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);
                            BlackBerryContact contact = (BlackBerryContact)contacts.choose();

                            if(contact!=null){
                                    int numValues = 0;
                                    numValues = contact.countValues(BlackBerryContact.TEL);
                                    for (int i = 0; i < numValues; i++) {
                                            if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
                                                    mobileNumber = contact.getString(BlackBerryContact.TEL, i);
                                                    break;
                                            }
                                    }
                            }

for JDE 4.2

Code:

BlackBerryContactList contacts = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
                            BlackBerryContact contact = (BlackBerryContact)contacts.choose(null,BlackBerryContactList.AddressTypes.PIN,true);

                            if(contact!=null){
                                    int numValues = 0;
                                    numValues = contact.countValues(BlackBerryContact.TEL);
                                    for (int i = 0; i < numValues; i++) {
                                            if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
                                                    mobileNumber = contact.getString(BlackBerryContact.TEL, i);
                                                    break;
                                            }
                                    }
                            }

Hope it will help u..

sonia1986 09-17-2009 05:29 AM

Quote:

Originally Posted by pgoeol (Post 1472351)
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);
                            BlackBerryContact contact = (BlackBerryContact)contacts.choose();

                            if(contact!=null){
                                    int numValues = 0;
                                    numValues = contact.countValues(BlackBerryContact.TEL);
                                    for (int i = 0; i < numValues; i++) {
                                            if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
                                                    mobileNumber = contact.getString(BlackBerryContact.TEL, i);
                                                    break;
                                            }
                                    }
                            }

for JDE 4.2

Code:

BlackBerryContactList contacts = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
                            BlackBerryContact contact = (BlackBerryContact)contacts.choose(null,BlackBerryContactList.AddressTypes.PIN,true);

                            if(contact!=null){
                                    int numValues = 0;
                                    numValues = contact.countValues(BlackBerryContact.TEL);
                                    for (int i = 0; i < numValues; i++) {
                                            if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
                                                    mobileNumber = contact.getString(BlackBerryContact.TEL, i);
                                                    break;
                                            }
                                    }
                            }

Hope it will help u..

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

sonia1986 09-17-2009 07:01 AM

Quote:

Originally Posted by sonia1986 (Post 1473029)
Hello
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?

Hello i get a solution this 2 but unable to call my app through that app
This is class which append the menu in native address book.
Code:

package device.pim;

import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.Dialog.*;


public final class MenuTest extends Application {
    private static long ID = 0x7cab1e23b72a0033L;
   
    public static void main(String[] args) {
        MenuTest app = new MenuTest();
        app.enterEventDispatcher();
    }
   
    MenuTest() {
        System.out.println("Registering MenuTest");
        long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST ;
        ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
        ApplicationMenuItem imagemenu = new DemoMenuItem();
        ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor();
        amir.addMenuItem(locationToAddMenuItem , imagemenu, app);

    }
 
    private static class DemoMenuItem extends ApplicationMenuItem {
        DemoMenuItem() {
            super(20);
        }
       
        public String toString() {
            return "Send ABC SMS";
        }
       
 public Object run(Object context) {

        if (context instanceof String) {
          //  new PIMDemo().enterEventDispatcher();
            return context;
            }
    return context;
  }
}
}


Code:

/*
This is my app which i want call from upper class..
package device.pim;
import net.rim.device.api.ui.*;

public final class PIMDemo extends UiApplication
{   
    private EventScreen _eventScreen;
 
  // Entry point for application
    public static void main(String[] args)
    {
        new PIMDemo().enterEventDispatcher();
    }   
   
    // Constructor
    private PIMDemo()
    { 
        // Create a new EventScreen and push screen onto stack.
        _eventScreen = new EventScreen();       
        pushScreen(_eventScreen);
        //new ContactsDemo().enterEventDispatcher();
    }
}

Thanks in advance..plzz reply soon

vivartpandey 09-17-2009 07:57 AM

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;
}

MobileDeveloperUK 01-30-2010 07:01 PM

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.