1

如何从 BB 的本机书籍中附加的菜单项进行呼叫('从 ABC 呼叫'选项)?

4

1 回答 1

8

以编程方式发起呼叫

对于 RIM OS 4.7 及更低版本,请使用Invoke

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

对于声明的 RIM OS 5.0,我们可以使用Phone.initiateCall方法:

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

请参阅从 BlackBerry 设备应用程序拨打电话(多线路环境)

将自定义菜单项添加到 BlackBerry 应用程序

要将您的“通过 ABC 呼叫”项目添加到地址簿菜单,我们需要执行以下操作:

现在,实现自定义菜单项:

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

现在将其添加到通讯录中:

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

放在一起

  • 运行应用程序
  • 按通话按钮
  • 选择联系人
  • 打开菜单

你应该看到

地址簿菜单 http://img9.imageshack.us/img9/8175/callviaabc.png

在 Bold 9000 模拟器上测试
完整代码:

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);
    }
}
于 2009-09-21T11:05:26.127 回答