BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-14-2009, 06:52 AM   #1
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default open native address book

Please Login to Remove!

How to open native address book from java app of blackberry phone and select a phone number in textfield?
Offline  
Old 09-14-2009, 08:09 AM   #2
vivartpandey
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 9000
Carrier: Airtel
Posts: 81
Default

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;
}
__________________
blog.vimviv.com
Offline  
Old 09-15-2009, 03:06 AM   #3
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by vivartpandey View Post
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..
Offline  
Old 09-15-2009, 04:01 AM   #4
pgoeol
Thumbs Must Hurt
 
Join Date: Sep 2009
Model: 8100
PIN: N/A
Carrier: Airtel
Posts: 75
Default

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.
Offline  
Old 09-15-2009, 06:53 AM   #5
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by pgoeol View Post
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..

Last edited by sonia1986; 09-15-2009 at 06:55 AM..
Offline  
Old 09-15-2009, 07:25 AM   #6
vivartpandey
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 9000
Carrier: Airtel
Posts: 81
Default

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.
__________________
blog.vimviv.com
Offline  
Old 09-15-2009, 08:14 AM   #7
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by vivartpandey View Post
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);
Offline  
Old 09-15-2009, 10:43 AM   #8
pgoeol
Thumbs Must Hurt
 
Join Date: Sep 2009
Model: 8100
PIN: N/A
Carrier: Airtel
Posts: 75
Default

Quote:
Originally Posted by sonia1986 View Post
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...
Offline  
Old 09-16-2009, 04:29 AM   #9
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by pgoeol View Post
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..
Offline  
Old 09-16-2009, 05:37 AM   #10
pgoeol
Thumbs Must Hurt
 
Join Date: Sep 2009
Model: 8100
PIN: N/A
Carrier: Airtel
Posts: 75
Default

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...
Offline  
Old 09-16-2009, 07:55 AM   #11
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by pgoeol View Post
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..
Offline  
Old 09-16-2009, 09:18 AM   #12
pgoeol
Thumbs Must Hurt
 
Join Date: Sep 2009
Model: 8100
PIN: N/A
Carrier: Airtel
Posts: 75
Default

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..
Offline  
Old 09-17-2009, 05:29 AM   #13
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by pgoeol View Post
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?
Offline  
Old 09-17-2009, 07:01 AM   #14
sonia1986
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 7110
PIN: N/A
Carrier: engg.
Posts: 19
Default

Quote:
Originally Posted by sonia1986 View Post
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
Offline  
Old 09-17-2009, 07:57 AM   #15
vivartpandey
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 9000
Carrier: Airtel
Posts: 81
Default

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;
}
__________________
blog.vimviv.com
Offline  
Old 01-30-2010, 07:01 PM   #16
MobileDeveloperUK
Thumbs Must Hurt
 
Join Date: Jan 2010
Model: 8300
PIN: N/A
Carrier: T-Mobile
Posts: 62
Default

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
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


A54MA55B and BC186A413G52 frequency converters A500/F540 series 55KW drive board picture

A54MA55B and BC186A413G52 frequency converters A500/F540 series 55KW drive board

$350.00



New Greaseweazle V4.1 USB Floppy Adapter Flux Reader Writer Amiga PC Case 1598 picture

New Greaseweazle V4.1 USB Floppy Adapter Flux Reader Writer Amiga PC Case 1598

$36.05



Dentistry Replacement NSK TiMAX NL95M/ A500/ A500L/ AK500L/ AS500L /AW500L NEW picture

Dentistry Replacement NSK TiMAX NL95M/ A500/ A500L/ AK500L/ AS500L /AW500L NEW

$79.95



MITSUBISHI A500 / FR-A540-5.5K-NA INVERTER 3PH  picture

MITSUBISHI A500 / FR-A540-5.5K-NA INVERTER 3PH

$108.00



MITSUBISHI FR-A820 1.5K TFA INVERTER A500 240 V #L-220 picture

MITSUBISHI FR-A820 1.5K TFA INVERTER A500 240 V #L-220

$684.00



1PC USED A54MA55B BC186A413G52 Mitsubishi A500/F540 Series 55KW Drive Board #CZ picture

1PC USED A54MA55B BC186A413G52 Mitsubishi A500/F540 Series 55KW Drive Board #CZ

$317.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.