09-26-2009 10:33 AM
I have developed a simple program to add a custom menu to the email application. The program works in simulator. The custom menu shows up in the email application and the action from the menu works. However, when I install the application in an actual device OTA, even though the device indicates the application has been installed successfully and shows up on the application list, but I don't see any menu in the email application. I also tried to add the menu to other application but it does not show up either. I am using JDE 4.5.0.7, default simulator for testing, and 8900 as the actual device for testing. I signed the application with RIM Blackberry Apps API (According to JDE this is the only one required), RIM Runtime API (not required), and RIM Crypto API (Optional).
I know it should work but I just can't make it work. I have searched the forum but can't seem to find out why I have this problem. Please let me know if there is anything I did that is incorrect. Much appreciated. I have inserted the code below:
public final class Demo extends Application { Demo() { try { ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance(); ApplicationMenuItem menu = new DemoMenuItem(); ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor
(); amir.addMenuItem( ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW , menu, app ); } catch( Throwable t ) { //ControlledAccessException thrown if access is denied accessing the location Dialog.alert( "Unable to initialize Demo " + t.toString() ); } } private static class DemoMenuItem extends ApplicationMenuItem { private Address[] addresses = null; DemoMenuItem() { super( 20 ); try { addresses = new Address[]{ new Address( "demo@demo.com", "Demo" ) }; } catch( Throwable t ) { System.out.println( "Unable to create application menu" ); } } public String toString() { return "Demo"; } public Object run ( Object aMessage ) { if ( aMessage instanceof Message ) { Message emailMessage = (Message)aMessage; emailMessage = emailMessage.forward(); try { emailMessage.addRecipients( Message.RecipientType.TO, addresses ); Transport.send( emailMessage ); } catch( Throwable t ) { t.printStackTrace(); System.out.println( "Unable to send message" ); } return emailMessage; } else { throw new IllegalStateException( "Expected an email object" ); } } } public static void main ( String[] args ) { Demo app = new Demo(); app.enterEventDispatcher(); }}
09-26-2009 11:05 AM
Just a guess, but I think you are probably hitting a controlled-access violation (ApplicationPermissions).
If the menu uitem is being added from in the startup context (not the event thread), then you will never see your exception dialog.
Did you pull the event log form the device and look for exceptions?
Also, try changing the dialog to a System.out.println() and attach the device to the debugger (you should see your text in the JDE output window).
One further suggestion: use ApplicationPermissionsManager to detect what the permissions are, and use this mechanism to set the correct permissions and prompt the user to accept them.
09-26-2009 03:36 PM
Thanks for the information. That is what I suspect but I thought I set to grant all permissions but will double check that again and will also try to debug directly in the device. Do you know potentially what permission will that be?
In regarding to "menu item is being added from in the startup context", I assume if I need to add that through the event thread then I will need a user interface application to do so, correct?
I did look at the system log but can't seem to find anything meaningful....
09-26-2009 03:43 PM
If your applicaiton is "auto-run", then your app will be called during startup to take care of things like listeners, etc.
It will be called a second time when the user clicks on your icon, this time with a different parm and a different context.
If your app is not aust-start then you can ignore my comment.
I guess you are down to old-fashioned debugging. Put some trace println's in there and connect the device to the debugger.
09-26-2009 06:17 PM
03-12-2010 02:54 AM