Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom
Accepted Solution

Disable Added System Menu Items

Hi Everyone

 

I have got quite a tricky question maybe someone can help me....

 

When adding MenuItems to Blackberry applications via your application is there a possibility of disabling those MenuItems If a specific screen is currently not open or if the app is currently not open?

 

If Yes Please Explain.....

 

thank you

Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: Disable Added System Menu Items

net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository
public static final long MENUITEM_ADDRESSBOOK_LIST 5911208747185054768L
public static final long MENUITEM_ADDRESSCARD_EDIT -1011653757168863700L
public static final long MENUITEM_ADDRESSCARD_VIEW -5544721730296222436L
public static final long MENUITEM_ALARM 7343976597688173750L
public static final long MENUITEM_BROWSER -7149655706782283261L
public static final long MENUITEM_CALENDAR -2786162410658704605L
public static final long MENUITEM_CALENDAR_EVENT 5182228461004335870L
public static final long MENUITEM_CAMERA_PREVIEW 3494724165262157040L
public static final long MENUITEM_EMAIL_EDIT 5244072729690617291L
public static final long MENUITEM_EMAIL_VIEW -6481681929958323011L
public static final long MENUITEM_FILE_EXPLORER 3504265587951702900L
public static final long MENUITEM_FILE_EXPLORER_BROWSE -7944553129300517756L
public static final long MENUITEM_FILE_EXPLORER_ITEM -2166984963208053554L
public static final long MENUITEM_GROUPADDRESS_EDIT -8839945759096901113L
public static final long MENUITEM_GROUPADDRESS_VIEW -2362642699356376043L
public static final long MENUITEM_MAPS 4804476335504286437L
public static final long MENUITEM_MEMO_EDIT 1967755168374878363L
public static final long MENUITEM_MEMO_LIST -7444654586207082127L
public static final long MENUITEM_MEMO_VIEW -446032573701822616L
public static final long MENUITEM_MESSAGE_LIST -2204303273264560528L
public static final long MENUITEM_MMS_EDIT 2946406880720845997L
public static final long MENUITEM_MMS_VIEW 5529224403653746205L
public static final long MENUITEM_MUSIC_SERVICE_ITEM -4053315241904586732L
public static final long MENUITEM_PHONE 7558275355255656232L
public static final long MENUITEM_PHONELOG_VIEW 2810978548042580997L
public static final long MENUITEM_SEARCH -2516548103282563172L
public static final long MENUITEM_SMS_EDIT 4101976187669332923L
public static final long MENUITEM_SMS_VIEW 9096799525298506811L
public static final long MENUITEM_SYSTEM 8522643724050848398L
public static final long MENUITEM_TASK_EDIT -5653680829824974669L
public static final long MENUITEM_TASK_LIST -4137793966879797982L
public static final long MENUITEM_VIDEO_RECORDER -3452314990895942416L
public static final long MENUITEM_VIDEO_SERVICE_ITEM -3908744855636860781L

 

 

you can select where do you want to display the menu item...

and its not possible to disable menuitems on 3rd party application

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Disable Added System Menu Items

I have successfully added a menu itmem, is it possible to disable the menu item I added? to uninvoke the menu item?

Developer
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900
My Carrier: MTN

Re: Disable Added System Menu Items

The same way you register it, you can deregister it:

 

ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
								amir.removeMenuItem(ApplicationMenuItemRepository."Wherever you've registered it", "Your menu item");

 

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Disable Added System Menu Items

note that you have to remove the exact same menu item you registered. you can use runtimestore to "remember" the menu item you registered and to check if it is already registered.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Disable Added System Menu Items

FieldChangeListener PhotoListener = new FieldChangeListener() {
			public void fieldChanged(Field field, final int context) {
				ButtonField  Button = (ButtonField) field;
				final RuntimeStore store = RuntimeStore.getRuntimeStore();
				Object obj = store.get(ID);
				if (Button.getLabel().equals("Take a Photo?")){ 
					Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
					testAMIR = ApplicationMenuItemRepository.getInstance();
					
					ami = new ApplicationMenuItem(0){ 
						public Object run(Object object) {
							UiApplication.getUiApplication().requestForeground();
							Dialog.alert("MenuItem 0 Clicked");
							
							ID = 0x63ac754bc0867248L; 
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,this);       
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,this);   
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,this);   
							repository.removeMenuItem(ID, this); 
							repository.removeMenuItem(ID, this); 
							repository.removeMenuItem(ID, this);
							return object;
						}
						public String toString() {
							return "Add Photo to Deal(0)";
						}
					};
					ami1 = new ApplicationMenuItem(1){ 
						public Object run(Object object) {
							ID = 0x64ac754bc0867248L; 
							/*if(ami != null) {
								ApplicationMenuItemRepository.getInstance().
								removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami);
								repository.removeMenuItem(ID, ami);
								store.put( ID, ami );
							}if(ami1 != null) {
								ApplicationMenuItemRepository.getInstance().
								removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami1);
								repository.removeMenuItem(ID, ami1); 
								store.put( ID, ami1 );
							}if(ami2 != null) {
								ApplicationMenuItemRepository.getInstance().
								removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami2);
								repository.removeMenuItem(ID, ami2); 
								store.put( ID, ami2 );
							}*/
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami);       
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,this);   
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,this);   
							repository.removeMenuItem(ID, ami); 
							repository.removeMenuItem(ID, this); 
							repository.removeMenuItem(ID, this);
							UiApplication.getUiApplication().requestForeground();
							Dialog.alert("MenuItem 1 Clicked");
							return object;
						}
						public String toString() {
							return "Add Photo to deal(1)";
						}
					};
					ami2 = new ApplicationMenuItem(2){ 
						public Object run(Object object) {
							ID = 0x65ac754bc0867248L; 
							/*if(ami != null) {
								ApplicationMenuItemRepository.getInstance().
								removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami);
								repository.removeMenuItem(ID, ami);
								store.put( ID, ami );
							}if(ami1 != null) {
								ApplicationMenuItemRepository.getInstance().
								removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami1);
								repository.removeMenuItem(ID, ami1); 
								store.put( ID, ami1 );
							}if(ami2 != null) {
								ApplicationMenuItemRepository.getInstance().
								removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami2);
								repository.removeMenuItem(ID, ami2); 
								store.put( ID, ami2 );
							}*/
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami);       
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami1);   
							ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,this);   
							repository.removeMenuItem(ID, ami); 
							repository.removeMenuItem(ID, ami1); 
							repository.removeMenuItem(ID, this);
							UiApplication.getUiApplication().requestForeground();
							Dialog.alert("MenuItem 2 Clicked");
							return object;
						}
						public String toString() {
							return "Add Photo to Deal(2)";
						}
					};
					if(obj == null){
						ApplicationDescriptor myApplicationDescriptor = new ApplicationDescriptor(ApplicationDescriptor.currentApplicationDescriptor(), "My Application Descriptor Name", new String[] {"A", "B"} );
						ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami ,myApplicationDescriptor);       
						ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami1 ,myApplicationDescriptor);   
						ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami2 ,myApplicationDescriptor);   
						repository.addMenuItem(ID, ami); 
						repository.addMenuItem(ID, ami1); 
						repository.addMenuItem(ID, ami2); 
						try{
							store.put( ID, ami );
							store.put( ID, ami1 );
							store.put( ID, ami2 );
						} catch(IllegalArgumentException e){
						}
					}else {
						ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami);       
						ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami1);   
						ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_CAMERA_PREVIEW,ami2);   
						repository.removeMenuItem(ID, ami); 
						repository.removeMenuItem(ID, ami1); 
						repository.removeMenuItem(ID, ami2); 
						try{
							store.remove( ID );
							store.remove( ID );
							store.remove( ID );
						} catch(IllegalArgumentException e){
						}
					}	
				};

 Simon_Hain I would Like to remove all of the MenuItems I added When the user clicks on one of the added menuItems.What the above code does is it only removes the menuitem that was clicked , I know you said I can Remove the MenuItem Where I reg it, Please can you look at my code and give me some advice on how to fix my problem.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Disable Added System Menu Items

i would suggest that you use an utility method for that, for example static in your main class.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Disable Added System Menu Items

Okay thank you Simon, it seemed to do the trick, one last thing..Once The MenuItem has been Selected I want to go back to the last screen accessed in the app, currently I am using :

UiApplication.getUiApplication().requestForeground();

 This Piece of Code pushes me back to the splash Screen, is there any way to open that specific screen or is there a way to pop the camera app or close it? Most of the threads I read about this dont really make sense to me.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Disable Added System Menu Items

you have to be aware of the application menu items often not running in the context of your own application, so if you use getUiApplication you might not get your own app, which can lead to unwanted (or wanted...) side effects.

to open a specific screen of your app i would suggest sending a global event and handling it in your app.
to close the camera screen, dunno, usually people use event injection with escape key i think.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Disable Added System Menu Items

ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
							ApplicationPermissions ap = new ApplicationPermissions();
							if(apm.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_DENY) {
								ap.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
								ReasonProvider rp = new ReasonProvider() {
									public String getMessage(int permissionID) {
										if(permissionID == ApplicationPermissions.PERMISSION_INPUT_SIMULATION) {
											return "<an explanation of why you need the permission>";
										}
										return null;
									}
								};
								try{
									apm.addReasonProvider(ApplicationDescriptor.currentApplicationDescriptor(), rp);
									
								}catch(IllegalArgumentException e) {
								}
								apm.invokePermissionsRequest(ap);
							}

 The above code pushes the wrong screen to the stack and then the below link looks like it could be useful but i am not able to figure out how it works http://stackoverflow.com/questions/1292896/blackberry-simulate-a-keypress-event

 

Do you maybe know of any helpful and easy to understand links?? thank you