2012-04-13 2 views
0

BB에서 이메일로 여러 이미지를 첨부하고 싶습니다. 어떻게해야합니까? 어떤 시체에 아이디어가 있습니까? 제발 도와주세요. 아래 코드는 이메일로 하나의 이미지 만 보낼 때 잘 작동합니다. 그래서 여러 이미지를 첨부하기 위해 내 코드에서 어떤 수정을해야합니까?Blackberry에서 이메일로 여러 개의 이미지를 첨부하려면 어떻게해야합니까?

public static void SendMailAttachment(Bitmap screenshot) 
      {    

       String htmlContent = "String" ;  
        try 
        { 
         Multipart mp = new Multipart(); 
         Message msg = new Message(); 
         Address[] addresses = {new Address("","")}; 

        for (int i = 0; i<2 ; i++) 
        { 
          PNGEncodedImage img = PNGEncodedImage.encode(screenshot); 
          SupportedAttachmentPart pt = new SupportedAttachmentPart(mp, img.getMIMEType(), 
          "Weed.png", img.getData()); 
          mp.addBodyPart(pt); 

         } 
          msg.setContent(mp); 
          msg.setContent(htmlContent); 

         msg.addRecipients(RecipientType.TO, addresses); 
         msg.setSubject("Subject");   
         Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(msg)); 

        } 
        catch (AddressException ex) 
        { 
         System.out.println("Exception -->"+ex.getMessage()); 
        } 
        catch (MessagingException ex) 
        { 
         System.out.println("Exception -->"+ex.getMessage()); 
        } 

     } 

고지.

답변

2

코드를 사용하여 여러 개의 이미지 또는 파일을 첨부 할 수 있습니다. 나는이 코드를 사용했다

public void upload() 
    {  
     Multipart mp = new Multipart(); 
    String fileName = null; 



    for (int i = 0; i<2 ; i++) 
    { 


     //   Dialog.alert(image.); 
     byte[] stream = readStream("file:///SDCard/IMG00001-20110404-1119.JPEG"); 
     SupportedAttachmentPart sap = new SupportedAttachmentPart(mp, MIMETypeAssociations.getMIMEType("IMG00001-20110404-1119.JPEG"),"IMG00001-20110404-1119.JPEG", stream); 
     mp.addBodyPart(sap); 

    } 


    TextBodyPart tbp = new TextBodyPart(mp,"test bodyString"); 
    mp.addBodyPart(tbp); 

    Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT); 
    Message message = new Message(folders[0]); 
    Address[] toAdds = new Address[1]; 

    try { 
     toAdds[0] = new Address("testmailid", null); 
     message.addRecipients(Message.RecipientType.TO,toAdds); 
     //   message.setFrom(new InternetAddress(_from)); 

     //   message.addRecipients(Message.RecipientType.FROM,toAdds); 
     message.setContent(mp); 
     message.setSubject("test subject"); 
     Transport.send(message); 

     Dialog.alert("message send successfully."); 

    } catch (AddressException e) { 
     // TODO Auto-generated catch block 
     //   e.printStackTrace(); 
     Dialog.alert(e.getMessage()); 

    } catch (MessagingException e) { 
     // TODO Auto-generated catch block 
     //   e.printStackTrace(); 
     Dialog.alert(e.getMessage()); 
    } 
} 

private byte[] readStream(String path) 
{ 


InputStream in = null; 
    FileConnection fc = null; 
byte[] bytes = null; 

try 
{ 
    fc = (FileConnection) Connector.open(path); 
    if (fc !=null && fc.exists()) 
    { 
     in = fc.openInputStream(); 
     if (in !=null) 
     { 
      bytes = IOUtilities.streamToBytes(in); 
     } 
    } 
} 
catch(IOException e) 
{ 

} 
finally 
{ 
    try 
    { 
     if (in != null) 
     { 
      in.close(); 
     } 
    } 
    catch(IOException e) 
    {     
    } 
    try 
    { 
     if (fc !=null) 
     { 
      fc.close(); 
     } 
    } 
    catch(IOException e) 
    {     
    } 

}  
return bytes;   

}. 그것은 잘 작동합니다.

+0

고맙습니다. 재생을 위해 .. – Hasmukh

+0

http://chat.stackoverflow.com/rooms/4014/knowledge-sharing-center-for-blackberry-android-and-java – Hasmukh

+0

당신은 readstream 메소드를 넣을 수 있습니까? – Hasmukh

1

SupportedAttachmentPart을 각 이미지에 새로 만들고 addBodyPart 방법으로 메시지에 추가하기 만하면됩니다.

멀티 파트가 본문 부분과 첨부 부분으로 채워지면 msg.setContent(mp)으로 전화하십시오.

+0

답장을 보내 주신 분께 ... – Hasmukh

+0

나는 그런 식으로 생각하고 있습니다. 괜찮습니까? 경우 (나는 2 <; I = 0 int로 난 ++) \t \t \t \t \t \t {\t \t \t \t \t \t \t \t PNGEncodedImage IMG = PNGEncodedImage.encode (사진 1); \t \t \t \t \t \t SupportedAttachmentPart의 PT = 새로운 SupportedAttachmentPart (MP, img.getMIMEType() "Weed.png"img.getData()); \t \t \t \t \t mp.addBodyPart (pt); \t \t \t \t} – Hasmukh

+0

나는 2 번에 하나의 이미지를 붙이려고했으나 이미지로 첨부하지 않았다. 내가 실수를하고 있다는 것을 말해 줄 수 있습니까? – Hasmukh

관련 문제