2010-09-15 102 views
0

我有一個問題附加到黑莓電子郵件的圖像。將圖像附加到黑莓通過代碼電子郵件

在我的代碼我可以將用相機拍攝的PNG圖像,它是在附件可見,但是當我點擊發送郵件按鈕,我得到一個錯誤:

Email service does not support these types of attachments. Change the Send-Using field, or change the attachments

我的代碼:

try { 
    FileConnection file = (FileConnection)Connector.open(FILE_NAME); 
    if(file.exists()) 
    { 
     InputStream stream = file.openInputStream(); 
     buf = IOUtilities.streamToBytes(stream); 
     stream.close(); 
     file.close(); 
     SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"image/png","collision.png",buf); 
     //SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,jpegImage.getMIMEType() ,"collision.jpg",jpegImage.getData()); 
     TextBodyPart tbp = new TextBodyPart(mp,"Attachment test"); 
     TextBodyPart name = new TextBodyPart(mp,"Name:"+Name.getText().toString()); 

     mp.addBodyPart(tbp); 
     mp.addBodyPart(sap); 
     mp.addBodyPart(name); 

     Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT); 

     Message message = new Message(folders[0]); 

     try { 
      Address toAdd = new Address("[email protected]","test email"); 
      Address toAdds[] = new Address[1]; 
      toAdds[0] = toAdd; 
      message.addRecipients(Message.RecipientType.TO,toAdds); 
      message.setContent(mp); 
      message.setSubject("Service Request via Blackberry app"); 

      Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message)); 

      //Transport.send(message); 
     } 
     catch (Exception e) { 
      Dialog.inform(e.toString()); 
     } 
    } 
+2

這在模擬器上是正常的,在真實的設備上試一下,它會正常工作, – 2010-09-15 15:05:52

+0

Michael B:或許可以做出答案 – 2010-09-15 15:09:48

回答

1

這在模擬器上是正常的,在真實的設備上嘗試它,它會正常工作。

+0

好的,謝謝我會檢查它 – 2010-09-16 05:29:34