BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 03-02-2010, 04:23 AM   #1 (permalink)
New Member
 
Join Date: Mar 2010
Model: 7100T
PIN: N/A
Carrier: EES
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb cannot send image greater than 64KB

Please Login to Remove!

Hello everyone,

I am new to blackberry and i want to send an image through mail which is around 432KB large.But i am unable to do it.Can anyone help

Here is my code:

class SendEmail extends Thread
{
boolean bCanSend = false;
Store msgStore;
Folder[] folderList;
Folder outFolder;
Message msg;
Transport emailTransport;
String _emailTo,_emailBody;
Multipart mp ;
String str="Heart.png";
byte[] imgData;
private Bitmap image;
SupportedAttachmentPart sap;

String messageData = "Mail Attachment Demo";

SendEmail(String emailTo,String emailBody)
{
try
{
Session s = Session.getDefaultInstance();
image = Bitmap.getBitmapResource("Heart.png");
imgData = getBytesFromBitmap(image);
System.out.println("trying to create session");
mp = new Multipart();

if(s == null)
{
String errMsg = "Unabled to send email message.\n";
Dialog.alert(errMsg);
bCanSend = false;

}
else
{
System.out.println(" created session");
bCanSend = true;
sap = new SupportedAttachmentPart(mp, "image/bmp","Heart.bmp",imgData);
TextBodyPart tbp = new TextBodyPart(mp,messageData);

//add the file to the multipart
mp.addBodyPart(tbp);
mp.addBodyPart(sap);

_emailTo = emailTo;
_emailBody = emailBody;
System.out.println("Body part added");
emailTransport = Session.waitForDefaultSession().getTransport();
msgStore = Session.waitForDefaultSession().getStore();
folderList = msgStore.list(Folder.SENT);
outFolder = folderList[0];
msg = new Message(outFolder);
System.out.println(" session method end");
}

}
catch(NoSuchServiceException nse)
{
nse.toString();
}


}

public byte[] getBytesFromBitmap(Bitmap bmp)
{
try {

System.out.println("converting bitmap");
int height=bmp.getHeight();
int width=bmp.getWidth();
int[] rgbdata = new int[width*height];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
Graphics g = new Graphics(bmp);
bmp.getARGB(rgbdata,0,width,0,0,width,height);
for (int i = 0; i < rgbdata.length ; i++) {
if (rgbdata[i] != -1)
{
dos.writeInt(i);
dos.flush();
//l++;
}
}
bos.flush();
return bos.toByteArray();
}
catch (Exception ex)
{
Dialog.alert("getBytesFromBitmap: " + ex.toString()); return null; }
}


public void run()
{
System.out.println("SendEmail :: running");
if(bCanSend == true)
{
try
{
Address [] addresses = new Address[1];
addresses[0] = new Address(_emailTo, _emailTo);
msg.addRecipients(Message.RecipientType.TO, addresses);
msg.setSubject("IBM Calendar Share!");
msg.setContent(mp);
emailTransport.send(msg);
System.out.println("Email has been sent");
}
catch(Exception e)
{
System.out.println("Exception caught trying to send email: " +
e.toString());
}
}
}
}



I know that SupportedAttachmentPart cannot send or receive more than 64KB but i found no other way for attachment. need this for project.This is urgent.Please help


Thanks in advance
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

SIEMENS 6ES7 951-1KK00-0AA0, SIMATIC S7, MEMORY CARD 1MB, NEW #248962
$849.2
SIEMENS 6ES7 951-1KK00-0AA0, SIMATIC S7, MEMORY CARD 1MB, NEW #248962 pictureFlashcat USB Memory Programmer BIOS MSI EEPROM NAND SPI JTAG I2C SERIAL (include
$59.97
Flashcat USB Memory Programmer BIOS MSI EEPROM NAND SPI JTAG I2C SERIAL (include pictureDATAPAQ MP0030A MEMORY PAQ *USED*
$120.0
DATAPAQ MP0030A MEMORY PAQ *USED* pictureM25P05-AVMN6TP SOP-8 Nor Flash Memory M25P05 Micron(ST)
$10.87
M25P05-AVMN6TP SOP-8 Nor Flash Memory M25P05 Micron(ST) pictureM29W320ET70N6E TSOP-48 32Mbit 4M/2Mx 8bit/16bit Parallel Flash Memory Micron(ST)
$3.19
M29W320ET70N6E TSOP-48 32Mbit 4M/2Mx 8bit/16bit Parallel Flash Memory Micron(ST) picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.