Blackberry - run menu item from dialer Phone App

巧了我就是萌 提交于 2019-12-22 09:25:53

问题


I'd like to describe one trick I learned at supportforums.blackberry.com

There is a native dialer Phone Application in BlackBerry.

The trick is to programmatically run menu items of dialer after incoming call, call fail or any other call event.


回答1:


There is a PhoneListener interface, which gives an ability to listen to the status of incoming and outgoing phone calls.

See Listen for and handle phone events

A quote from supportforums.blackberry.com - Re: How to exit an Ui application (by simon_hain):

Listeners are hard referenced by the application they are added to. Figuratively speaking, they become part of the rim application.

If you add a listener to the phone application this listener is executed in the context of the phone app.
You can check this by using Ui.getUiEngine().getActiveScreen() in a listener method. The returned screen is the call screen of the phone application.

I use this to execute commands on phone calls:
- on callInitiated or callConnected i store a reference to the phone screen.
- i call phoneScreen.getMenu(0)

now i want to execute a command:
- i change the locale to "en"
- i iterate through the menu using menu.getSize() and menu.getItem(i)
- i check if menuItem.toString equals my command
- i call menuItem.run()
- and change the locale back (if it was changed)

you can use this to:
mute
unmute
activate speakerphone
view speeddiallist
end the call (only prior to 4.5/4.6, not sure which one)
and many more. just print the available menu items :)

A sample code for this trick, on incoming call print all menu to console, on answer call mute phone on end call - unmute phone:

public class UseScreenMenu extends Application implements PhoneListener {
    String MENU_ITEM_MUTE = "Mute";
    String MENU_ITEM_UNMUTE = "Unmute";
    public UseScreenMenu() {
        Phone.addPhoneListener(this);
    }

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

    public void callIncoming(int callId) {
        printMenu();    
    }

    public void callAnswered(int callId) {
        runMenuItem(MENU_ITEM_MUTE);
    }

    public void callEndedByUser(int callId) {
        runMenuItem(MENU_ITEM_UNMUTE);  
    }

    private void printMenu() {      
        Screen screen = Ui.getUiEngine().getActiveScreen();
        Menu menu = screen.getMenu(0);
        System.out.println("Menu of BB Dialler - Begin");
        for (int i = 0, cnt = menu.getSize(); i < cnt; i++)
            System.out.println("Menu of BB Dialler - "
                +menu.getItem(i).toString());
        System.out.println("Menu of BB Dialler - End");     
    }

    private void runMenuItem(String menuItemText) {
        Screen screen = Ui.getUiEngine().getActiveScreen();
        Menu menu = screen.getMenu(0);
        for (int i = 0, cnt = menu.getSize(); i < cnt; i++)
            if(menu.getItem(i).toString().equalsIgnoreCase(menuItemText))
                menu.getItem(i).run();
    }


    public void callAdded(int callId) {}
    public void callConferenceCallEstablished(int callId) {}
    public void callConnected(int callId) {}
    public void callDirectConnectConnected(int callId) {}
    public void callDirectConnectDisconnected(int callId) {}
    public void callDisconnected(int callId) {}
    public void callFailed(int callId, int reason) {}
    public void callHeld(int callId) {}
    public void callInitiated(int callid) {}
    public void callRemoved(int callId) {}
    public void callResumed(int callId) {}
    public void callWaiting(int callid) {}
    public void conferenceCallDisconnected(int callId) {}
}


来源:https://stackoverflow.com/questions/1533057/blackberry-run-menu-item-from-dialer-phone-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!