开发者

Using ApplicationMenuItem to override default message sender in RIM API

开发者 https://www.devze.com 2023-01-11 15:08 出处:网络
I was wondering if there was any way to make an ApplicationMenuItem inside the message edit screen that, when selected sends the message to the selected contacts itself, bypassing the default sending

I was wondering if there was any way to make an ApplicationMenuItem inside the message edit screen that, when selected sends the message to the selected contacts itself, bypassing the default sending program. I am fine with the menu item and have seen how to do similar things by retrieving the 'context' argum开发者_开发知识库ent but I'm not sure how I would get the message body and contacts that were selected.


In ApplicationMenuItem of message edit context will be an instance of net.rim.blackberry.api.mail.Message

See code:

package so.samples;

import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MessageArguments;
import net.rim.blackberry.api.mail.Address;
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.mail.MessagingException;
import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;

public class SOComposeMsgMenuApp extends UiApplication {

    public static void main(String[] args) {
        (new SOComposeMsgMenuApp()).enterEventDispatcher();
    }

    public SOComposeMsgMenuApp() {
        ApplicationMenuItem emailMenuItem = new ApplicationMenuItem(0) {
            public Object run(final Object context) {
                if (context instanceof Message) {
                    StringBuffer text = new StringBuffer("Message \nTo:\n");
                    Message msg = (Message) context;
                    Address[] to = new Address[] {};
                    try {
                        to = msg.getRecipients(Message.RecipientType.TO);
                    } catch (MessagingException e) {
                    }
                    for (int i = 0; i < to.length; i++) {
                        text.append(to[i].toString());
                        text.append("\n");
                    }
                    text.append("Body:\n");
                    text.append(msg.getBodyText());
                    Dialog.inform(text.toString());
                }
                return context;
            }

            public String toString() {
                return "My Menu Item";
            }
        };

        ApplicationMenuItemRepository amir = ApplicationMenuItemRepository
                .getInstance();
        amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_EMAIL_EDIT,
                emailMenuItem);
        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
                new MessageArguments(MessageArguments.ARG_NEW, "", "testing",
                        "just trying to test menu item from compose screen"));
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号