BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-16-2008, 12:19 PM   #1 (permalink)
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

One further item to check on, access to the MenuRepository requires signatures.
Offline  
Old 07-17-2008, 07:05 PM   #9 (permalink)
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
New Member
 
Join Date: Jun 2008
Location: Dallas, TX
Model: 8330
PIN: N/A
Carrier: Sprint
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
New Member
 
Join Date: Sep 2006
Location: India
Model: 8800
PIN: 23F577A3
Carrier: Airtel
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 10:13 PM   #15 (permalink)
New Member
 
Join Date: Jan 2009
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 10:14 PM.
Offline  
Old 01-20-2009, 03:30 AM   #16 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 09:55 AM   #17 (permalink)
New Member
 
Join Date: Jan 2009
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 02:30 AM   #18 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 03:45 PM   #19 (permalink)
New Member
 
Join Date: Jan 2009
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

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

Thanks.
Offline  
Old 01-22-2009, 03:14 AM   #20 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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