本文整理汇总了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());
}
}
示例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);
}
}
});
}