0
我想知道是否有任何方法可以在消息編輯屏幕內部創建一個ApplicationMenuItem,當選擇將消息發送給所選聯繫人本身時,繞過默認發送程序。我對菜單項很滿意,並且已經看到如何通過檢索「上下文」參數來做類似的事情,但我不知道如何獲得選定的消息正文和聯繫人。使用ApplicationMenuItem覆蓋RIM API中的默認消息發送方
我想知道是否有任何方法可以在消息編輯屏幕內部創建一個ApplicationMenuItem,當選擇將消息發送給所選聯繫人本身時,繞過默認發送程序。我對菜單項很滿意,並且已經看到如何通過檢索「上下文」參數來做類似的事情,但我不知道如何獲得選定的消息正文和聯繫人。使用ApplicationMenuItem覆蓋RIM API中的默認消息發送方
在消息編輯環境的ApplicationMenuItem將是net.rim.blackberry.api.mail.Message
見代碼的實例:
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"));
}
}