当前位置: 首页>>代码示例>>Java>>正文


Java Message.getAttachment方法代码示例

本文整理汇总了Java中com.codename1.messaging.Message.getAttachment方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getAttachment方法的具体用法?Java Message.getAttachment怎么用?Java Message.getAttachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codename1.messaging.Message的用法示例。


在下文中一共展示了Message.getAttachment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import com.codename1.messaging.Message; //导入方法依赖的package包/类
public void sendMessage(String[] recipients, String subject, Message msg) {
    Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);
    net.rim.blackberry.api.mail.Message message = new net.rim.blackberry.api.mail.Message(folders[0]);
    try {
        Address toAdds[] = new Address[recipients.length];
        for (int i = 0; i < recipients.length; i++) {
            Address address = new Address(recipients[i], "");
            toAdds[i] = address;
        }
        message.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAdds);
        message.setSubject(subject);
    } catch (Exception e) {
        EventLog.getInstance().logErrorEvent("err " + e.getMessage());            
    }

    try {

        if (msg.getAttachment() != null && msg.getAttachment().length() > 0) {
            Multipart content = new Multipart();
            TextBodyPart tbp = new TextBodyPart(content,msg.getContent());                
            content.addBodyPart(tbp);
            
            InputStream stream = com.codename1.io.FileSystemStorage.getInstance().openInputStream(msg.getAttachment());
            byte[] buf;
            buf = IOUtilities.streamToBytes(stream);
            stream.close();
            String name = msg.getAttachment();
            name = name.substring(name.lastIndexOf(getFileSystemSeparator()) + 1, name.length());
            SupportedAttachmentPart sap = new SupportedAttachmentPart(content, msg.getAttachmentMimeType(), name, buf);
            content.addBodyPart(sap);                
            message.setContent(content);
        } else {
            message.setContent(msg.getContent());
        }

        app.setWaitingForReply(true);
        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
    } catch (Exception ex) {
        EventLog.getInstance().logErrorEvent("err " + ex.getMessage());
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:42,代码来源:BlackBerryImplementation.java

示例2: sendMessage

import com.codename1.messaging.Message; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public void sendMessage(String[] recipients, String subject, Message msg) {
    if(editInProgress()) {
        stopEditing();
    }
    Intent emailIntent;
    String attachment = msg.getAttachment();
    boolean hasAttachment = (attachment != null && attachment.length() > 0) || msg.getAttachments().size() > 0;
        
    if(msg.getMimeType().equals(Message.MIME_TEXT) && !hasAttachment){
        StringBuilder to = new StringBuilder();
        for (int i = 0; i < recipients.length; i++) {
            to.append(recipients[i]);
            to.append(";");
        }
        emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.parse(
                "mailto:" + to.toString()
                + "?subject=" + Uri.encode(subject)
                + "&body=" + Uri.encode(msg.getContent())));        
    }else{
        if (hasAttachment) {
            if(msg.getAttachments().size() > 0) {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                ArrayList<Uri> uris = new ArrayList<Uri>();
                
                for(String path : msg.getAttachments().keySet()) {
                    uris.add(Uri.parse(fixAttachmentPath(path)));
                }
                
                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            } else {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                emailIntent.setType(msg.getAttachmentMimeType());
                //if the attachment is in the uder home dir we need to copy it 
                //to an accessible dir
                attachment = fixAttachmentPath(attachment);
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachment));
            }
        } else {
            emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            emailIntent.setType(msg.getMimeType());
        }
        if (msg.getMimeType().equals(Message.MIME_HTML)) {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent()));                                
        }else{
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());                    
        }
        
    }
    final String attach = attachment;
    AndroidNativeUtil.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), new IntentResultListener() {

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(attach != null && attach.length() > 0 && attach.contains("tmp")){
                FileSystemStorage.getInstance().delete(attach);
            }
        }
    });
}
 
开发者ID:shannah,项目名称:cn1,代码行数:72,代码来源:AndroidImplementation.java


注:本文中的com.codename1.messaging.Message.getAttachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。