How To Programmatically receive Attachment
where i can find example about getting attachment from a Message (mail API)?
I already implement folderlistener, and its messagesAdded(FolderEvent).
I got Message from FolderEvent, Message as instanceof Multipart.
the Multipart consist of 2 BodyParts,
my attachment in BodyPart index number 1.
I check bodypart.hasMore() it's true, means any content in server.
I call Transport.more(bodyPart, true);
but the bodypart.hasMore() always true (i try to loop about 2 minutes,
but it's always true).
My attachment only about 100 Bytes.
when i check message.getClass().getName() its
belong to UnSupportedAttachmentPart with size == 0.
is it any example how to get attachment by program?
thank you ..
you have to implement an attachmenthandler for your content-type first.
you have to prefix your file with x-rimdevice or it will not be delivered to your handheld (you could change some settings on the bes, alternatively).
i will try it first.
i will rename my attachment to: x-rimdevice-filename.ext
about the attachment handler, should i register to AttachmentManager
before i can get the attachment (BodyPart index number 1) via Transport.More()?
or register to Attachment as just an option for blackberry to recognize
my attachment as instanceof SupportedAttachmentPart?
i already read your post (in 2005) about retrieve attachment,
now i have same problem, i can't getContent() because it size==0.
add the attachment handler in an autorun part of your project (see kb article), your second assumption is correct, the system needs to know the filetype to be able to deliver a SupportedAttachmentPart.
Be aware of Attachments not supporting hasMore().
thanks for your attention.
My application is not an autostart app.
I create app that when it executed, it will waiting for FolderEvent,
I already successful while getting Multipart from Event's Message.
i already change my filename to: x-rimdevice-filename.ext
so the attachment will store in handheld (right?).
and its content-type is: application/x-myapp
I add AttachmentHandler in my appMainScreen constructor,
when i get BodyPart from Multipart (my attachment on index number 1),
the bodypart's size is 0.
but return true on method bodypart.hasMore().
is it any error on my attachment handler registration?
because when i check into the message,
and press menu on message's attachment, the menu "View ATT"
is not shown.
any other clue?
Some things to think about. As of OS 4.1, registering your attachment handler object with the AttachmentHandlerManager should be a one-time only event. This is because the OS caches the object, and does not release/delete it. So if your application is registering an attachment handler every time your app launches, another one will be added to the list the OS is caching. This is why you should only register your attachment handler with the OS once for every time the device is turned on - this can be arranged through an "Alternate Entry Point" mechanism.
One more thing: sometimes attachment handlers are unable to respond to attachments in email messages that arrived before the attachment handler was registered. I say "sometimes" because the behavior is somewhat inconsistent (i.e., I used to notice this behavior consistently on OS 4.1 and earlier devices, but I have some tests which have shown that this is not necessarily true on 4.2 or later devices).
thanks for your information.
about the attachment handler registration,
i addHandler at appMainScreen constructor,
and i removeHandler when user close() the app.
so the handler is one time handler like what you said.
about the sequence of the message,
in this test case, of course i send the message (email),
after i open my application.
so, it should be catch by the handler.
Until now, i still can't do sap.getContent().
I don't know it's caused by error when registering handler
or it's error because of i can't get more() attachment from server.
So, just out of curiosity, would you be willing to try an experiment and use an Alternate Entry Point to attach your attachment handler? I've never tried to do it the way you suggest, and for the application I have developed, this has always worked.
That is, with a few exceptions - Sprint's version of device OS 4.3.X does not work with email attachments very well. Our testing failed every single time, and RIM admitted that Sprint had accepted a version with a bug in the email attachment handling mechanism. Luckily no other service provider is using 4.3.X. However, early releases of OS 4.5 also contain the same bug, and several were accepted by Rogers Wireless and Vodafone Germany. There may be one or two others I've left off the list. So if you're using a 4.3 simulator and/or a 4.3-based device, email attachment handling may not work correctly (I think I was seeing failure in both the simulators and real devices).
then main problem is name of content-type.
don't know why, the blackberry system don't allow
me to use my own name likes "application/x-myapps".
the blackberry will detect as application/octet-stream.
i register attachment handler, and print out every
message that have attachment via EventLogger.
now, my application run well,
attachment handler register at application open,
and attachment handler remove at application close.
Hey, congratulations and thanks for reporting success! And the details! You're on your way to answering posts now!
|All times are GMT -5. The time now is 03:46 AM.|
Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.