tags:

views:

20

answers:

1

Hello,

I am trying to create my own a menu item in built-in Contacts application. And when clicking on that menu item will have to launch my application with the contact details which has chosen.

I could able to add my own menu item into native Contacts app menu. It is showing it on BB 4.7 Simulator.

amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST, contactsDemoMenuItem);

I am trying to launch my application screen with detail of the selected contact.

I follow the code for that,

 public class SampleMenuItem extends ApplicationMenuItem
{
    Contact mContact;
    SampleMenuItem()
    {
        super(20);
    }
     public Object run(Object context)
    {

        if (context instanceof Contact) 
         {
                 mContact = (Contact) context;

           pushScreen(new MyAppNextScreen(<Here i need to pass a string which should have contact name and mobile number appended>));

        }

        return context;
    }

But when a click on menu item from native contacts, it is succedully launching to my application. No issues here too. But i want to know how can i pull up the selected contact detail from Native contact to my application. I use "context instanceof Contact". I have to go through the record and pick only contact name and mobile number. How can i achieve it?

Thank you.

A: 

I resolved everything finally.

 public Object run(Object context)
    {            
        if (context instanceof Contact) {

            mContact = (Contact) context;

            String data;
           StringBuffer strOut = new StringBuffer();

           String[] dataArray = mContact.getStringArray(Contact.NAME, 0);

           if((data = dataArray[Contact.NAME_GIVEN]) != null)
            {
                strOut.append(data);

            }
           int n = mContact.countValues(Contact.TEL);
           for(int i=0; i<n; i++)
            {
                data = mContact.getString(Contact.TEL, i);
                strOut.append(" - ");                   

                strOut.append(data);
                if(Contact.ATTR_WORK == mContact.getAttributes(Contact.TEL, i))
                    strOut.append("(Work Phone)");
                else if(Contact.ATTR_MOBILE == mContact.getAttributes(Contact.TEL, i))
                    strOut.append("(Mobile Phone)");
                else if(Contact.ATTR_HOME == mContact.getAttributes(Contact.TEL, i))
                    strOut.append("(Home Phone)");
                else if(Contact.ATTR_FAX == mContact.getAttributes(Contact.TEL, i))
                    strOut.append("(Fax NO)");
                else if(Contact.ATTR_PAGER == mContact.getAttributes(Contact.TEL, i))
                    strOut.append("(Page NO)");
            }

            catch(Exception e)
            {
                System.out.println("No Email Address");
            }

            UiApplication.getUiApplication().pushScreen(new MyAppNextScreen(strOut.toString()));

        }