BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-16-2008, 12:19 PM   #1
nomadicon
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Default Adding a menu item to the Phone

Please Login to Remove!

Hello all,

My application wishes to add a menu item to the Phone's menu. The API makes this relatively straightforward, using ApplicationMenuItemRepository.MENUITEM_PHONE. However, my menu item does not show up in the Phone application's menu.

When I use ApplicationMenuItemRepository.MENUITEM_SYSTEM instead, it does show up, but then, of course, it shows up in every application's menu.

To get around this, I use the PhoneListener interface to add the menu item when a call is connected and remove it when a call is disconnected, but that doesn't completely solve the problem: if I switch to another application while a call is connected, the menu item is there. I can implement my MenuItem so that it doesn't actually do anything unless the menu item was chosen from the Phone application, and unless there's a way to get MENUITEM_PHONE to work the way it should, that is what I'll do.

Is there some special voodoo I'm missing when using ApplicationMenuItemRepository.MENUITEM_PHONE, or is this a new or documented bug?

Using JDE 4.3.

Thanks in advance,
Scott S.
Offline  
Old 07-16-2008, 01:12 PM   #2
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

Scott,

Seems to work fine on JDE 4.2.1. Can you post a more complete code snippet?
Offline  
Old 07-16-2008, 06:50 PM   #3
nomadicon
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Default Example

Here's the relevant code, which isn't very complicated:
// _menuItem extends ApplicationMenuItem, initialized earlier...

ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance();
repository.addMenuItem(ApplicationMenuItemReposito ry.MENUITEM_PHONE, _menuItem);
Whenever the phone app is up, though, the menu item does not appear in the phone's menu. Only when I change MENUITEM_PHONE to MENUITEM_SYSTEM does it show up.

It works neither on the simulator nor on the real device. I am most perplexed.
Offline  
Old 07-17-2008, 08:53 AM   #4
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

Where did "ry" get initialized? You should use the static reference anyway,

ApplicationMenuItemRepository.MENUITEM_PHONELOG_VI EW and
ApplicationMenuItemRepository.MENUITEM_PHONE

You will defintely need to add both items, in my experience. You initial look at the phone is in the "VIEW" mode, so that might be why you don't see the menu item.
Offline  
Old 07-17-2008, 09:02 AM   #5
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

ooops - sorry, the format got fargled in my browser - I see now that you did use the static reference. Anyway, try adding the "PHONELOG_VIEW" and see if that one works.
Offline  
Old 07-17-2008, 12:31 PM   #6
nomadicon
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Default

Thanks for your efforts in helping, Doug.

Well, using both PHONELOG_VIEW and PHONE seems to do me no good. Here's the sequence of events (the code formatter will probably mangle it somewhat):
// These will do the same thing, but I've seen in other forum posts that
// adding the same menu item twice won't work

_menuItem1 = new MyMenuItem();
_menuItem2 = new MyMenuItem();

_appForMenuItem1 = ApplicationMenuItemRepository.MENUITEM_PHONELOG_VI EW;
_appForMenuItem2 = ApplicationMenuItemRepository.MENUITEM_PHONE;
The menu item shows up in neither the Phone app, nor in the Phone Log app.

Unless I'm doing something wrong, I'm going to leave it the way I have it, using the MENUITEM_SYSTEM approach with special handling. The deadline approacheth.
Offline  
Old 07-17-2008, 01:16 PM   #7
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Are you ever registering the menu item? This would happen if you ran your program first, but if you just install your app the the menu item wouldn't get registered (I'm not sure why the system-level option is working).

I use an alternate entry point to do menu item registrations (note that you also need to do a little config outside of code to do alternate entry points which is covered in the Knowledge Base). You need to set the non-gui entry point to auto start and be a system module.

The code below registers a menu item for the Addressbook, but I did a little test against the Phone app and it worked as well (just need to change the constant). The "process" method is just where you'd process anyobjects sent to your menu item from the native app.

Code:
	public static void main(String[] args) {
		if (args != null && args.length > 0 && args[0].equals("gui")){
			App app = new App();
			app.enterEventDispatcher();
		}
		else {
			AddressBookRegistration.register();
		}
	}
Code:
public class AddressBookRegistration {

	public static void register() {
		ApplicationMenuItem item = new ApplicationMenuItem(0) {
			public Object run(Object context) {
				process(context);
				return context;
			}
			public String toString() {
				return "My Menu Item";
			}
		};

		ApplicationMenuItemRepository.getInstance().addMenuItem(
				ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST, item);
	}
	
	public static void process(Object context) {
		if (! (context instanceof Contact)) {
			return;
		}

                // Blah blah blah
	}

}
__________________
Do your homework and know how to ask a good question.
Offline  
Old 07-17-2008, 02:15 PM   #8
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

One further item to check on, access to the MenuRepository requires signatures.
Offline  
Old 07-17-2008, 07:05 PM   #9
nomadicon
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Default

I am indeed registering it at device startup, and I do have the required code signatures. But as I mentioned earlier, this problem manifests itself in both the simulator as well as on the device.

I changed the ApplicationMenuItemRepository constant to MENUITEM_ADDRESSBOOK_LIST and MENUITEM_CALENDAR, and it worked in both cases. Yet changing it back to MENUITEM_PHONE results in no menu item.

I'm downloading the newly-released JDE 4.5, in the hopes that this issue will be addressed.

Interestingly, and this may point to the cause of the problem, the context variable in my menu item's run() method is null when selected from the Phone app. (This is when I got the menu item added using the _SYSTEM constant.) Does this raise any red flags? Does the _PHONE constant require special consideration?
Offline  
Old 07-17-2008, 07:13 PM   #10
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Weird, man. I'm using 4.2.1 and it's working...

One thing to note is that all you'll ever get for the context is either null (if you're dialing a number) or a PhoneCallLog object representing the most recent entry in the call log - neither of which are terribly useful to anyone, IMO.

Could you post the code that you use to create _menuItem? (or a link to the whole thing if it's not too big)
__________________
Do your homework and know how to ask a good question.
Offline  
Old 07-17-2008, 07:45 PM   #11
nomadicon
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Default

Sure, here's all the code:

main:
Code:
public static void main(String[] args) 
    {
        if (args.length == 1 && args[0].equals("startup")
        {
            // register the menu item at device startup
            AppStartup.register();
        }
        else
        {
            MyApplication app = new MyApplication();
            app.enterEventDispatcher();
        }
    }
AppStartup:
Code:
    final static class AppStartup {
        public static void register() {
            MyMenuItem menuItem = new MyMenuItem(0);
            ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONE, menuItem);
        }
    }
MyMenuItem:
Code:
public final class MyMenuItem extends ApplicationMenuItem 
{
    public MyMenuItem(int order) 
    {
        super(order);
    }

    public String toString()
    {
        return "My Menu Item";
    }
    
    public Object run(Object context)
    {
        // Do something interesting

        return context;
    }
}
Offline  
Old 07-17-2008, 07:57 PM   #12
nomadicon
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Default

Unfortunately, the upgrade to JDE 4.5 seems to have had no effect on this particular problem.
Offline  
Old 07-17-2008, 09:19 PM   #13
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Can you post your jad (or .rapc) file? I want to see if the alternate entry point set up correctly. Otherwise, the code itself looks ok. Thx.

One other thing to try quickly is to delete all of your derived files (like .jad, .rapc, .debug, etc), rebuild, and try again. When you change app properties they might not get picked up - need to nuke the existing files and let rapc generate them again from scratch.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 07-30-2008, 01:57 AM   #14
emmanuelfrancis
New Member
 
Join Date: Sep 2006
Location: India
Model: 8800
PIN: 23F577A3
Carrier: Airtel
Posts: 2
Default MENUITEM_PHONE Display on PhoneLog

I am also facing the same issue with 4.2.1 JDE. What I have noticed that adding menu using "MENUITEM_PHONE" add menu to the screen where user type a number and make a call. But this does not add custom menu to the calling screen where it shows "Connected...".

I have attached the screen shots for the details.

Is it possible to add the custom menu to the 2nd screen?
Attached Images
File Type: png phonemenu1.png (22.0 KB, 29 views)
File Type: png phonemenu2.png (20.4 KB, 32 views)
Offline  
Old 01-19-2009, 11:13 PM   #15
OctavianBanica
New Member
 
Join Date: Jan 2009
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 3
Default context always null.

Quote:
Originally Posted by richard.puckett View Post
Weird, man. I'm using 4.2.1 and it's working...

One thing to note is that all you'll ever get for the context is either null (if you're dialing a number) or a PhoneCallLog object representing the most recent entry in the call log - neither of which are terribly useful to anyone, IMO.

Could you post the code that you use to create _menuItem? (or a link to the whole thing if it's not too big)


Hi Richard,

I built a java application that adds a menu item to the call log menu. My problem is when I select a call log and run that menu item, the context is always null. Do you have any idea when the context is null and when is a PhoneCallLog object?

I create the same menu item in the message menu (MENUITEM_MESSAGE_LIST), and from there everything is ok. The context is always a PhoneCallLog object.

I do not understand the difference.

(I use a bb 9000 simulator).

Octavian.

Last edited by OctavianBanica; 01-19-2009 at 11:14 PM..
Offline  
Old 01-20-2009, 04:30 AM   #16
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

the context of the call log is null in some OS versions. it is supposedly fixed in the latest, but i did not test it.
as your menuitem runs in the context of the phone application you can use getActiveScreen to retrieve the screen of the phone application.
use getFieldWithFocus to get the current field or iterate through the fields to find the correct one and read its text value.
it is kind of a hack but works on all versions.
(the missing context object kept me and rim support busy for some months back then)
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 01-20-2009, 10:55 AM   #17
OctavianBanica
New Member
 
Join Date: Jan 2009
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 3
Default

Thanks,

I tried the following sequence:

public Object run(Object context)
{
if (context == null)
{
Screen screen = UiApplication.getUiApplication().getActiveScreen() ;
Field screenField = screen.getFieldWithFocus();
}
}

But the Field class (object returned by getFieldWithFocus()) doesn't have a getText() method. How can I get the phone number from the selected entry from the call log screen?

I tried to use :

if (screenField instanceof TextField)
{
String number = ((TextField)screenField).getText();
}

and it worked for the pone numbers manually entered in this screen. It doesn't work for the selected entry from the call log.
Offline  
Old 01-21-2009, 03:30 AM   #18
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

as the call log is an internal implementation you can not cast your object to it. there is no way to retrieve it.
i have rebuilt the whole phonescreen in an application of mine, the only backdraw is that the lookup methods are increadibly slow when used on a big addressbook (like 3minutes to find contacts with a single letter on 800 entries).
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 01-21-2009, 04:45 PM   #19
OctavianBanica
New Member
 
Join Date: Jan 2009
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 3
Default

Hi,

Is there a way to get the selected entry from the call log?

Thanks.
Offline  
Old 01-22-2009, 04:14 AM   #20
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

there is no way to retrieve it
__________________
java developer, Devinto, hamburg/germany
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


OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$42.80



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$49.90



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$35.90



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$37.90



Genuine OEM A1417 Battery For Apple Macbook Pro 15

Genuine OEM A1417 Battery For Apple Macbook Pro 15" Retina A1398 2012 2013 NEW

$38.90



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$49.90







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