BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-13-2005, 12:43 AM   #1
yzoer
New Member
 
Join Date: Aug 2004
Posts: 8
Default Custom Attachment Handler

Please Login to Remove!

Hi All,

Using the BB example code for creating a custom attachment handler I can't seem to get a valid pointer to my data using getContent(). Anyone been here before?


-Yvo
Offline  
Old 04-15-2005, 02:35 PM   #2
yzoer
New Member
 
Join Date: Aug 2004
Posts: 8
Talking

In one word: RTFM... The devil's in the details!
Offline  
Old 09-05-2007, 11:44 AM   #3
Johan_Fox
New Member
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 5
Default

I don't know how to getContent() either. It doesn't return anything.

What manual should I read??! I think I must've read them all searching for the answer to this one...
Offline  
Old 09-05-2007, 11:59 PM   #4
arifzaman
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Default

Hi,

The following code sample shows how to create an Attachment Handler on the BlackBerry device. This application adds a menu option of View File to the email display screen menu if the message contains a Wireless Markup Language (WML) file attachment.

Code:
import net.rim.blackberry.api.mail.*;
import net.rim.blackberry.api.mail.event.*;
import net.rim.device.api.system.*;

class AttachmentViewer extends Application implements AttachmentHandler {

    public static void main(String args[]) {
        AttachmentViewer theApp = new AttachmentViewer();
    }

    public AttachmentViewer() {
        //Add this AttachmentHandler to the AttachmentHandlerManager
        AttachmentHandlerManager m = AttachmentHandlerManager.getInstance();
        m.addAttachmentHandler(this);
    }

    //Called when a new email message arrives to see if it is supported
    //by this AttachmentHandler (this sample supports wml).
    //If it is true then the menu item will be shown in the message screen.
    public boolean supports(String contentType) {

        boolean val;

        if (contentType.toLowerCase().indexOf("wml") != -1)
            val = true;
        else
            val = false;

        return val;
    }

    //Then menu item that will appear from the message screen
    public String menuString() {
        return "View File";
    }

    //Runs when the user selects the above defined menu item
    public void run(Message m, SupportedAttachmentPart p) {
        //Perform required processing on your attachment here.
        //Get the attachment filename.
        System.out.println("WML filename: " + p.getFilename());
        //Get the attachment size.
        System.out.println("Attachment size is: " + p.getSize());
        //Get the contents of the attachment.
        byte[] temp = (byte[])p.getContent();
        String data = new String(temp);
        System.out.println("Attachment Content: " + data);

    }
}
Hope, this will help!

Cheers,
ARIF
Offline  
Old 09-06-2007, 04:11 AM   #5
Johan_Fox
New Member
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 5
Default Custom attachment handler

Thank you for your help.

This is the same sample code that I have been playing with.

However... in this section:

byte[] temp = (byte[])p.getContent();
String data = new String(temp);
System.out.println("Attachment Content: " + data);



p.getContent() returns some raw data, which isn't useful. But then, the String 'data' is empty. This should hold the contents of the attachment in a readable format.

I'm not able to read the contents of an attachment.

Jon
Offline  
Old 03-25-2008, 07:17 AM   #6
Johan_Fox
New Member
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 5
Default

I have figured this out now.

The file extension is not recognised by BES, and needs to be added to the attachment service list of supported file types. Then the file is ACTUALLY sent to the handset, rather than just APPEARING to be on the handset.
Offline  
Old 06-24-2008, 12:55 PM   #7
louE
New Member
 
Join Date: Apr 2008
Model: 8703e
PIN: N/A
Carrier: vfw
Posts: 3
Default Test this on the sim

Does anyone know how to test this with the simulator? I have the attachment, but the length of the retrieved contents is 0. Is this configurable on the MDS simulator?
Offline  
Old 06-24-2008, 02:46 PM   #8
louE
New Member
 
Join Date: Apr 2008
Model: 8703e
PIN: N/A
Carrier: vfw
Posts: 3
Default test this on the sim

To the poor soul who reads this next. Apparently all you have to do is append x-rimdevice to your attachment name. So if you are sending file.test rename it x-rimdevicefile.test and suddenly your attachment is no longer 0 bytes in length.

Blackberry forum post where I found the answer
Offline  
Old 07-18-2008, 08:47 AM   #9
schwarzbeere29829
New Member
 
Join Date: Jul 2008
Model: 8300
PIN: N/A
Carrier: od did
Posts: 12
Default

Quote:
Originally Posted by louE View Post
To the poor soul who reads this next. Apparently all you have to do is append x-rimdevice to your attachment name. So if you are sending file.test rename it x-rimdevicefile.test and suddenly your attachment is no longer 0 bytes in length.

...
did you configure thath with the email server simulator?

I used the x-rimdevice filename and content is still null.
Offline  
Old 07-18-2008, 08:54 AM   #10
skicson
Thumbs Must Hurt
 
Join Date: Mar 2008
Location: Columbia, MD
Model: 8130
PIN: N/A
Carrier: verizon
Posts: 95
Default

It should work fine with the MDS simulator. If you are receiving the email in the simulator and if your attachment has size (e.g. is not 0 bytes) then it may still be an issue with the filename.

Just to confirm, the "x-rimdevice" is prepended (not appended) to the filename as in:
x-rimdevicemyfilename.test


Quote:
Originally Posted by schwarzbeere29829 View Post
did you configure thath with the email server simulator?

I used the x-rimdevice filename and content is still null.
Offline  
Old 07-18-2008, 09:40 AM   #11
schwarzbeere29829
New Member
 
Join Date: Jul 2008
Model: 8300
PIN: N/A
Carrier: od did
Posts: 12
Default

Quote:
Originally Posted by skicson View Post
It should work fine with the MDS simulator. If you are receiving the email in the simulator and if your attachment has size (e.g. is not 0 bytes) then it may still be an issue with the filename.

Just to confirm, the "x-rimdevice" is prepended (not appended) to the filename as in:
x-rimdevicemyfilename.test
it is preprended.

But the thing with the MDS Simulator is interesting for me.

You are sure, that you don't mean the Email Server Simulator?

Since I'm a beginner with this topic, I don't even know what the MDS Simulator is and how to use it (apart from starting).

It does not open a window for E-Mail configuration and such things.
Offline  
Old 07-18-2008, 09:45 AM   #12
skicson
Thumbs Must Hurt
 
Join Date: Mar 2008
Location: Columbia, MD
Model: 8130
PIN: N/A
Carrier: verizon
Posts: 95
Default

oh sorry, yes, you are correct ESS, not MDS. MDS is for BES/BIS type web connections
Offline  
Old 07-18-2008, 09:48 AM   #13
skicson
Thumbs Must Hurt
 
Join Date: Mar 2008
Location: Columbia, MD
Model: 8130
PIN: N/A
Carrier: verizon
Posts: 95
Default

if you are getting the email into the simulator, you should be okay wrt ESS settings.
Offline  
Old 02-12-2009, 09:50 AM   #14
ramakrishnat
New Member
 
Join Date: Aug 2008
Model: 8800
PIN: N/A
Carrier: Tmobile
Posts: 3
Default

I am able to handle attachment. But, I need a viewer to view the attachment.
According to my understading, AttachmentService will convert the attachmented file into UCS format. and Client software display that content in blackberry.

Is there any way to customize the attachmentService.

Means:
I created a custom attachment handler for doc file.
1. If the user click on any doc attachment then that will ping my server with the attachment name. At my server I need a program to convert it into UCS format.

2. A viewer(UserInterface) or some thing like this to view the content that came from my server as a responce.


I tried Apache POI to convert word file into text and display that text into RichTextField at device side. I was success in that. But, I am unable to handle format here.

Please give me suggestions.

Thanks,
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


NSA Enespro AGP 40cal Arc Flash Kit w/ Lift Front Hood, No Gloves ARC40KITNG-XL picture

NSA Enespro AGP 40cal Arc Flash Kit w/ Lift Front Hood, No Gloves ARC40KITNG-XL

$399.99



Schneider Electric XBTZGM256 256MB Compact Flash Card picture

Schneider Electric XBTZGM256 256MB Compact Flash Card

$212.23



Flash Furniture GO-7145-BK-GG Black Leather Executive Office Chair picture

Flash Furniture GO-7145-BK-GG Black Leather Executive Office Chair

$193.50



APOC 264  FLASH N' SEAL WHITE ELASTOMERIC ROOF & FLASHING SEALANT 2 GALLONS picture

APOC 264 FLASH N' SEAL WHITE ELASTOMERIC ROOF & FLASHING SEALANT 2 GALLONS

$79.99



LP Weather Logic Seam And Flashing Tape (boxes) picture

LP Weather Logic Seam And Flashing Tape (boxes)

$200.00



York 031-02755-003 CARD FLASH YCAL EXT RANGE MMHP picture

York 031-02755-003 CARD FLASH YCAL EXT RANGE MMHP

$236.34







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