1

how to make a call from menu item appended in native book of BB('Call from ABC' option)?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Do you actually want to programmatically make call to some phone number of contact from blackberry contact book? – Maksym Gontar Sep 21 '09 at 10:45
  • yes.when i clicked on contact in native address book from there i make a call by clicking appened option 'Call via ABC' option programmtically.. –  Sep 21 '09 at 11:24

1 Answers1

8

Initiate call programmatically

For RIM OS 4.7 and lower use Invoke:

PhoneArguments phoneArgs = new PhoneArguments(PhoneArguments.ARG_CALL,
    "555-5555");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, phoneArgs);

For RIM OS 5.0 declared we can use Phone.initiateCall method:

Phone.initiateCall(Phone.getLineIds()[0], "519-555-0100");

See Make a call from a BlackBerry device application (multi-line environment)

Add custom menu item to BlackBerry application

To add your "Call via ABC" item to address book menu we need to do following:

Now, implementing custom menu item:

class AdressBookMenuItem extends ApplicationMenuItem {
    Contact mContact;
    public AdressBookMenuItem(int order) {
        super(order);
    }
    public Object run(Object context) {
        if (context instanceof Contact) {
            mContact = (Contact) context;
            if (0 < mContact.countValues(Contact.TEL)) {
                String phone = mContact.getString(Contact.TEL, 0);
                PhoneArguments args = new PhoneArguments(
                        PhoneArguments.ARG_CALL, phone);
                Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
            } else {
                Dialog.alert("This contact has no phone number");
            }
        }
        return null;
    }
    public String toString() {
        return "Call via ABC";
    }
}

Now add it to the address book:

AdressBookMenuItem menuItem = new AdressBookMenuItem(0);
ApplicationMenuItemRepository repository = 
    ApplicationMenuItemRepository.getInstance();
long id = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
repository.addMenuItem(id, menuItem);

Putting All Together

  • Run application
  • Press Call button
  • Select contact
  • Open menu

You should see

address book menu http://img9.imageshack.us/img9/8175/callviaabc.png

Tested on Bold 9000 simulator
Full code:

import javax.microedition.pim.Contact;
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.PhoneArguments;
import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class CallIntegrate extends UiApplication {

    public CallIntegrate() {
        pushScreen(new Scr());
    }

    public static void main(String[] args) {
        CallIntegrate app = new CallIntegrate();
        app.enterEventDispatcher();
    }
}

class AdressBookMenuItem extends ApplicationMenuItem {
    Contact mContact;

    public AdressBookMenuItem(int order) {
        super(order);
    }

    public AdressBookMenuItem(Object context, int order) {
        super(context, order);
    }

    public Object run(Object context) {
        if (context instanceof Contact) {
            mContact = (Contact) context;
            if (0 < mContact.countValues(Contact.TEL)) {
                String phone = mContact.getString(Contact.TEL, 0);
                PhoneArguments args = new PhoneArguments(
                        PhoneArguments.ARG_CALL, phone);
                Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
            } else {
                Dialog.alert("This contact has no phone number");
            }
        }
        return null;
    }

    public Contact getContact() {
        return mContact;
    }

    public String toString() {
        return "Call via ABC";
    }
}

class Scr extends MainScreen {
    public Scr() {
        super(DEFAULT_MENU|DEFAULT_CLOSE);
        String label = "Now please go to blackberry adressbook, "
                + "select contact and open menu";
        add(new LabelField(label));

        AdressBookMenuItem menuItem = new AdressBookMenuItem(0);
        ApplicationMenuItemRepository repository = 
            ApplicationMenuItemRepository.getInstance();
        long id = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
        repository.addMenuItem(id, menuItem);
    }
}
Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114