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
Developer
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Creating custom menu item for forwarding message with phone number appended

Hi 

 

I have a requirement where in the blackberry sms application and additional men uitem needs to be added say "Forward With number" This option will allow the user to forward the selected message to another user with appending the users contact number in the message body.

 

For example I am reading a message send by A and I am forwarding it to B . While forwarding it the contact number of A should be appended in the message send to B. What needs to be done for this ?? Please provide some inputs to implement this.

Developer
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: Creating custom menu item for forwarding message with phone number appended

Any suggestion on this.
Is it possible to get a selected message details programtically using a Application Menu Item and get the text and sender details from it
Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Creating custom menu item for forwarding message with phone number appended

You should register your ApplicationMenuItem with: MENUITEM_SMS_EDIT & MENUITEM_SMS_VIEW.

 

This will ensure that the run method of your ApplicationMenuItem will get the relevant TextMessage.

 

Once you have the TextMessage you can get the Address and set the message data.

 

E.

Developer
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: Creating custom menu item for forwarding message with phone number appended

Any idea on how I will get the selected message details like sender number payload text etc ??

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Creating custom menu item for forwarding message with phone number appended

Developer
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: Creating custom menu item for forwarding message with phone number appended

I want to know how to select the particular message on which my current focus is present. Is there any way I can get it 

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Creating custom menu item for forwarding message with phone number appended

You should get it once the user clicked on your ApplicationMenuItem (provided that you registered your ApplicationMenuItem correctly).

 

Why don't you show us your code and tell us what happens when you try to click on your menu item?

 

We might be able to be more helpful if we will get more details...

 

E.

Developer
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: Creating custom menu item for forwarding message with phone number appended

Dear Maadani

 

Please find the below code which I have written for the above mentioned functionality. The main functionality is achieved but the Application Menu item is not appearing in SMS compose option. I want to display this option only when user is in the Text messaage screen only not in the email page but still its coming. Please help me to understand if am doing anything wrong in the below code

public class MenuDemo extends UiApplication {

    // one and only instance of our application
    static MenuDemo theApp = null;

	// constructor
    public MenuDemo()
    {
    	// setup menu(s)
        LMMenu lmm = new LMMenu(0);
        System.out.println("Menu 1");
        RuntimeStore store = RuntimeStore.getRuntimeStore();
        System.out.println("Menu 2");
        long menuItemId=0x65fad834642a5345L;
        if(store.get(menuItemId)==null){
        ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance();
        repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_MESSAGE_LIST, lmm);
        repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_SMS_VIEW, lmm);
        repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_SMS_EDIT, lmm);
        store.put(menuItemId, lmm);
        }
   }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
        theApp = new MenuDemo();
        if (theApp != null)
        {
            theApp.enterEventDispatcher();
        }
	}
}
class LMMenu extends ApplicationMenuItem {
	
	private Registry registry;
	
	public LMMenu(int order){
		super(order);
		System.out.println("Menu Last");
		registry = Registry.getRegistry(getClass().getName());
		System.out.println("Menu");
	}
	// TODO Auto-generated constructor stub}

	public Object run(Object context) {
		// TODO Auto-generated method stub
		if(context == null || !(context instanceof TextMessage)){
			System.out.println("Menu is Null");
			return null;
		}
		 TextMessage c = (TextMessage)context;
	        if (c != null) {
	            String sendTo = c.getAddress();
	            String msgBody = c.getPayloadText();
	            System.out.println("Send To"+sendTo+"Msg"+msgBody);
	            
				{
	            MyTextMessage m = new MyTextMessage();
	             m.setPayloadText( msgBody+"No:"+sendTo);
	             MessageArguments args = new MessageArguments(m);
	             Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, args);
				}
	         }
		return null;
	}

	public String toString() {
		// TODO Auto-generated method stub
		return "SMS Forward With Number";
	}
}

 

public class MyTextMessage implements TextMessage {

    private final Date _timestamp;
    private String _payloadText;
    private String _address;

    public MyTextMessage() {
        this._timestamp = new Date();
    }

    public String getAddress() {
        return this._address;
    }

    public String getPayloadText() {
        return this._payloadText;
    }

    public Date getTimestamp() {
        return this._timestamp;
    }

    public void setAddress(String address) {
        this._address = address;
    }

    public void setPayloadText(String payloadText) {
        this._payloadText = payloadText;
    }

}

 

Developer
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: Creating custom menu item for forwarding message with phone number appended

Any comments on the above code
Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Creating custom menu item for forwarding message with phone number appended

If you don't want to add this option for emails, comment out this line:

 

repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_MESSAGE_LIST, lmm);

E.