WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章手机编程BlackBerryBlackBerry 应用程序开发者指南 第二卷:高级--第2章 集成消息

BlackBerry 应用程序开发者指南 第二卷:高级--第2章 集成消息
作者:佚名  来源:本站整理  发布时间:2008-3-15 0:32:11

定义一个相关菜单项字符串

在消息列表中,当用户选择一个附件时,menuString()的实现返回一个显示的菜单项字符串.

public String menuString() {

    return "Custom Attachment Viewer";

}

定义附件处理

run()的实现完成了对附件的合理处理,并将附件显示给用户.

public void run(Message m, SupportedAttachmentPart p) {

    // Perform processing on data.

    Screen view = new Screen();

    view.setTitle(new LabelField("Attachment Viewer"));

    view.add(new RichTextField(new String((byte[])p.getContent())));

}

: 当在消息列表里选择相应的菜单项时,调用run()方法.

注册一个附件处理器

AttachmentHandlerManager类控制附件是如何在BlackBerry设备上处理的.当用户打开一个相关类型的附件时,为了使消息应用程序调用你的自定义附件,调用addAttachmentHandler()注册你的附件处理器.

:BES附件服务在接收附件时有第一优先级,第三方附件处理器不能覆盖缺省BlackBerry设备的行为,为获得更多信息,参看BES维护和疑难解答指南”.

AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();

CustomAttachmentHandler ah = new CustomAttachmentHandler();

m.addAttachmentHandler(ah);

获取附件

SupportedAttachmentPart类代表了一个BlackBerry设备上对应查看器的附件.BlackBerry设备上.,一个没有查看器的附件作为一个UnsupportedAttachmentPart表现.

获取附件内容

调用getContent().

String s = new String((byte[])p.getContent());

获取附件信息

SupportedAttachmentPart类提供多个方法获取附件信息.下面的例子调用getName()getSize()获取附件名和大小.

public void run(Message m, SupportedAttachmentPart p) {

     ...

     String name = p.getName();

     int size = p.getSize();

    }

发送一个带有附件的消息

通过创建一个新的Multipart对象创建一个多部分信息.为了创建每个附件组件,创建一个SupportedAttachmentPart的对象,Multipart作为它的父组件.为了把每个SupportedAttachmentPart增加到Multipart,调用对象上的addBodyPart(SupportedAttachmentPart).

当调用Message对象的setContent(Multipart), Multipart对象作为参数传入.

MultiPart multipart = new MultiPart(); // Default type of multipart/mixed.

SupportedAttachmentPart attach =

    new SupportedAttachmentPart( multipart, "application/x-example", "filename", data);

multipart.addBodyPart(attach); // Add the attachment to the multipart.

msg.setContent(multipart);

Transport.send(msg); // Send the message.

  • Last Updated:2007年1月23日
  • Last Updated:2006年4月28日

上一页  [1] [2] [3] [4] [5] [6] 

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码