BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 08-27-2007, 10:46 AM   #1
ungeildodger
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8700
PIN: N/A
Carrier: don't know
Posts: 15
Default SupportedEmailAttachment Problem

Please Login to Remove!

I have a problem, I have an own attachment handler with the following code:

Quote:
public final class RoamingAttachmentHandler implements AttachmentHandler {

public static final long RAH_ID = 0x7651702a598f81a5L;

public RoamingAttachmentHandler(){
AttachmentHandlerManager.getInstance().addAttachme ntHandler(this);
}

//Returns an instance of the running FolderListenerApp.
public static RoamingAttachmentHandler waitForSingleton(){
//Ensure this is a singleton instance.
System.out.println("start attaching...");
//Open the RuntimeStore.
RuntimeStore store = RuntimeStore.getRuntimeStore();
//Obtain the reference of FolderListenerApp.
Object obj = store.get(RAH_ID);

//If obj is null, there is no current reference
//to FolderListenerApp. Start a new instance
// of FolderListenerApp if one is not running.
if (obj == null){
System.out.println("done");
//Store a reference to this instance in the RuntimeStore.
store.put(RAH_ID, new RoamingAttachmentHandler());
return (RoamingAttachmentHandler)store.get(RAH_ID);
}
else{
System.out.println("it still is");
return (RoamingAttachmentHandler)obj;
}
}

public static void unregister(){
//Open the RuntimeStore.
RuntimeStore store = RuntimeStore.getRuntimeStore();
//Obtain the reference of FolderListenerApp.
Object obj = store.get(RAH_ID);

if (obj != null)
AttachmentHandlerManager.getInstance().removeAttac hmentHandler((AttachmentHandler) obj);
}

public boolean supports(String string) {
System.out.println("ich werde gefragt: " + string);
return string.indexOf("x-mtravel-roaming") > -1 || string.indexOf("roaming.mdata") > -1;
}

public String menuString() {
return "Roamingpreise aktualisieren";
}

public void run(Message message, SupportedAttachmentPart supportedAttachmentPart) {
System.out.println("i'm handling...");

if(supportedAttachmentPart.hasMore()){
System.out.println("there is more!");
try{
Session.getDefaultInstance().getTransport().more(s upportedAttachmentPart, true);
}
catch(Exception e){
System.out.println("somthing went wrong");
}
}

//Perform required processing on your attachment here.
//Get the attachment filename.
System.out.println("WML filename: " + supportedAttachmentPart.getFilename());
//Get the attachment size.
System.out.println("Attachment size is: " + supportedAttachmentPart.getSize());
//Get the contents of the attachment.
byte[] temp = (byte[])supportedAttachmentPart.getContent();
System.out.println("byte[].length: " + temp.length);
String data = new String(temp);
System.out.println("Attachment Content: " + data);
}
}
The Handler works fine, but I dont get the Content. My byte[] has always a length of 0.

The logfile givs me the follwing:

i'm handling...
trying to get more!
WML filename: roaming.mdata
Attachment size is: 145463
byte[].length: 0
Attachment Content:

I beleave it has something todo with the Transporter an that I don't get the content through the Transport.more ...

I have no Idea what I can do...

Pls. help
Offline  
Old 08-27-2007, 10:46 PM   #2
arifzaman
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Default

Hi ungeildodger,

Quote:
Originally Posted by ungeildodger View Post
public void run(Message message, SupportedAttachmentPart supportedAttachmentPart) {
System.out.println("i'm handling...");

if(supportedAttachmentPart.hasMore()){
System.out.println("there is more!");
try{
Session.getDefaultInstance().getTransport().more(s upportedAttachmentPart, true);
}
catch(Exception e){
System.out.println("somthing went wrong");
}
}

//Perform required processing on your attachment here.
//Get the attachment filename.
System.out.println("WML filename: " + supportedAttachmentPart.getFilename());
//Get the attachment size.
System.out.println("Attachment size is: " + supportedAttachmentPart.getSize());
//Get the contents of the attachment.
byte[] temp = (byte[])supportedAttachmentPart.getContent();
System.out.println("byte[].length: " + temp.length);
String data = new String(temp);
System.out.println("Attachment Content: " + data);
}
Following possible solutions for this issue:
Code:
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);
}
Cheers,
ARIF

Last edited by arifzaman; 08-27-2007 at 10:47 PM..
Offline  
Old 08-29-2007, 03:57 AM   #3
ungeildodger
Knows Where the Search Button Is
 
Join Date: May 2007
Model: 8700
PIN: N/A
Carrier: don't know
Posts: 15
Default

As you can see, this is similar to my example! I found this codepice to and while searching the error I added some stuff, but It doesn't work at all...
Offline  
Old 09-05-2007, 11:28 AM   #4
Johan_Fox
New Member
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 5
Default Custom attachment handler

I'm also having the same problem.

getContent returns nothing at all.

Has anyone got any advise?

Thanks in advance
Offline  
Old 09-07-2007, 12:26 AM   #5
Rose
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
Default

Hi,
Small suggestion regarding this instead of retrieving data using
(byte[])p.getContent();

get it as a object type itself and check whether the object is null or it has some values. If the object has value we can covert it to string or bytes afterwards.
Offline  
Old 09-07-2007, 12:32 AM   #6
Rose
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
Arrow

What i think is p.getContent() of tends to return a Object type which you are type casting to the byte array format may be this place some exception is thrown which possibly leads to the result
byte[].length: 0
Attachment Content:

do like this and check whether it throws an exception

String data = null;
try{
byte[] temp = (byte[])supportedAttachmentPart.getContent();
System.out.println("byte[].length: " + temp.length);
data = new String(temp);

}
catch(Exception ae){
//print the exception
}


if(data != null)
System.out.println("Attachment Content: " + data);
else
//Error on reading content

Hope this will help
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


Vintage Mitutoyo Vernier Caliper Machinist Tool Stainless Steel 9

Vintage Mitutoyo Vernier Caliper Machinist Tool Stainless Steel 9" Excellent

$39.99



Vintage Travel Alarm Clock Calendar Calculator Double Press Up Working + Battery picture

Vintage Travel Alarm Clock Calendar Calculator Double Press Up Working + Battery

$9.99



Dental Surgical TELESCOPIC  Glasses Surgery Vintage W/Case picture

Dental Surgical TELESCOPIC Glasses Surgery Vintage W/Case

$142.50



KP KOOL PRODUCTS Aftermarket Pre-Ban Chilton/Vintage Craftsman (1 YELLOW SPOUT) picture

KP KOOL PRODUCTS Aftermarket Pre-Ban Chilton/Vintage Craftsman (1 YELLOW SPOUT)

$14.99



GE TH3361 Safety Disconnect Switch Fusible 30 Amp 3 Pole 600VAC Model 2 Vintage picture

GE TH3361 Safety Disconnect Switch Fusible 30 Amp 3 Pole 600VAC Model 2 Vintage

$50.00







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