日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Attachments

發布時間:2024/8/1 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Attachments 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

附件

//創建一個附件處理器
  首先黑莓企業服務器服務獲得所有附件連線。第三方附件處理器不能修改默認的黑莓裝置的設置。
?//引入一下類
??? net.rim.blackberry.api.mail.Message
??? net.rim.blackberry.api.mail.SupportedAttachmentPart
??? net.rim.device.api.ui.Screen
??? net.rim.device.api.ui.component.LabelField
??? net.rim.device.api.ui.component.RichTextField
??? net.rim.blackberry.api.mail.AttachmentHandlerManager
?//引入net.rim.blackberry.api.mail.AttachmentHandler接口
?//實現AttachmentHandler接口,通過黑莓所承認 MIME的接口類定義附件處理事件
?//實現字符串的支持,在下列代碼例子,如果支持附件將返回一個Boolean。
??public boolean supports(String contentType) {
???return (contentType.toLowerCase().indexOf("contenttype") != -1 ? true : false);
??}
?//當黑莓用戶選擇一個附件,使用menuString()來定義相關的菜單項字符串列表顯示的消息時。
??public String menuString() {
???return "Custom Attachment Viewer";
??}
?//使用run()來定義附件的處理,當一個黑莓裝置用戶選擇一個菜單項的消息,這個動作調用run()方法。
??在以下的例子中,我們實行代碼創建了一個全新的屏幕標題‘Attachment Viewer’與使用RichTextField
??顯示一個字符串的內容附件。
??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())));
??}
?//調用AttachmentHandlerManager.addAttachmentHandler()注冊一個附件檔。當注冊一個自定義附件處理器,
??前綴名是“x-rimdevice”的附件派和儲存的黑莓裝置。
??AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();
??CustomAttachmentHandler ah = new CustomAttachmentHandler();
??m.addAttachmentHandler(ah);
??
//檢索附件的內容
?//引入net.rim.blackberry.api.mail.SupportedAttachmentPart類
?//調用SupportedAttachmentPart.getContent().
??String s = new String((byte[])p.getContent());
??
//檢索附件信息
?//引入 net.rim.blackberry.api.mail.SupportedAttachmentPart類
?//調用類SupportedAttachmentPart的方法。類SupportedAttachmentPart相當于黑莓裝置的附件觀察者。
??類UnsupportedAttachmentPart黑莓裝置沒有附件觀察者。

//發送一個帶附件的郵件
?//引入一下類
??? net.rim.blackberry.api.mail.Multipart
??? net.rim.blackberry.api.mail.SupportedAttachmentPart
??? net.rim.blackberry.api.mail.Message
??? net.rim.blackberry.api.mail.Session
??? net.rim.blackberry.api.mail.Transport
??? net.rim.blackberry.api.mail.MessagingException
?//創建Multipart類 multipart信息
??byte[] data = new byte[256]; // The attachment.
??MultiPart multipart = new MultiPart(); // Default type of multipart/mixed.
?//創建類SupportedAttachment,指定multipart的父類,在屏幕上創建每個插件
??SupportedAttachmentPart attach = new SupportedAttachmentPart( multipart,
??"application/x-example", "filename", data);
?//調用MultiPart.addBodyPart(SupportedAttachmentPart)
??multipart.addBodyPart(attach); // Add the attachment to the multipart.
?//調用Message.setContent(Multipart)與提供給類Multipart的參數設置附件內容
??msg.setContent(multipart);
?//調用Session.getTransport()和保存在一個可變對象的返回類型運輸。這個運輸對象代表了消息傳輸協議。
??Transport object represents the messaging transport protocol.
??Transport trans = Session.getTransport();
?//調用Transport.send(Message).
??try {
???trans.send(msg);
??} catch(MessagingException e) {
???System.out.println(e.getMessage());
??}

總結

以上是生活随笔為你收集整理的Attachments的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。