Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
Accepted Solution

Will Attachment Handler work for Mail Client??

[ Edited ]

Hi,

 

In my application, i am working with Attachments of the mail. So for this requirement, i used Custom Attachment Handler. But in the messages application, what ever the mail is there, for those only attachment handler is working. So i have the different mail accounts like gmail, yahoo mail. For those, the menu option is displaying, but it will not launching my application. Because it is reching to the run method:

 

public void run(Message m, SupportedAttachmentPart p)
{

}

 But as it is not the Message app, it is not able to open the application. In the documentation they mentioned that:  "The system invokes this method on the event thread of the Messages application".

 

So i want to know, whether the  mails from other application is possible to open? Is there really any other way??

And for the attachments, without  x-rimdevice prefix, why it is not working??

 

If anyone give some alternatives, it will be a very helpful for me..

 

Thanks..

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10

Not able to retrieve Attachment Content using Attachment Handler..

[ Edited ]

Hi,

 

 

I am trying to get the attachments content from Messages folder. But it is showing the empty string although it is returning the name and size properly. For every file(txt, html or else), it is not returning any string values. For this i am writing the below code:

 

 public boolean supports(String contentType)
	    {

	        boolean val;

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

	        return val;
	    }


 public void run(Message m, SupportedAttachmentPart p)
	    {
	    	MainScreen view = new MainScreen();
	    	view.setTitle("Attachment Viewer");
	    	view.add(new RichTextField(new String((byte[])p.getContent())));
	    	view.add(new RichTextField(new String(p.getFilename())));
//	    	PasswordScreen pwd = new PasswordScreen();
	    	Logger.out("eMailMinderApp", "Attachment Content" +new RichTextField(new String((byte[])p.getContent())));
	    	Ui.getUiEngine().pushGlobalScreen(view, 1, UiEngine.GLOBAL_QUEUE);
}

I am using BB 6 OS and connected with BIS.   

Can anyone please help me in this...thanks in advance..

 

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Will Attachment Handler work for Mail Client??

This should answer most of your questions.  If not, please post a follow up message.

 

Delivering attachment contents to a BlackBerry smartphone

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10

Re: Will Attachment Handler work for Mail Client??

Thanks Mark for your reply. I already have seen this link. But using AttchmentHandler, i am not getting the content of the attachment. Although i am using the same code as the given link is suggesting. If i am going to handle using AttachmentDownloadManager, the problem is,  It does not support forwarded or sent messages. So can you tell me how i can get the content of the attachment using AttachmentHAndler??

 

For that i already started a thread in this link: http://supportforums.blackberry.com/t5/Java-Development/Not-able-to-retrieve-Attachment-Content-usin...

 

And it is really annoying that how blackberry is handling the attachments compare to Android. Because, i am implementing the  same application in Android where it is really pretty easy. Sorry to say, BlackBerry s giving more options but no clarity although i am big fan of Blackberry Java Development.

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Will Attachment Handler work for Mail Client??

I've merged your threads so I can reply in one place.

 

AttachmentHandler is only able to access the contents of attachments that have their filename prefixed with x-rimdevice and for types that are not natively supported on the device.  That means you can't use that approach for .txt files, but you could create a new extension for your attachments so they are delivered.

 

Note that unless x-rimdevice is prefixed to an attachment, it is not delivered to the device.  The attachment remains on the user's mailbox and can be retrieved later by the user or by using AttachmentDownloadManager.  This was done to conserve wireless bandwidth.  The same process is true for messages you forward.  When a user forwards a message, attachments on the original email are not sent from the device.  They are pick up on the server side from the user's mailbox.  If a user attaches a new file locally on their device, then of course that one would need to be sent from the device.  So if you are reading a sent, forwarded message the attachment itself won't exist on the device.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10

Re: Will Attachment Handler work for Mail Client??

I have prefixed it with x-rimdevice and i am trying to get the content for html files..

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,649
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Will Attachment Handler work for Mail Client??

Try changing the extension to something else.  HTML would be a natively supported email attachment.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10

Re: Will Attachment Handler work for Mail Client??

Ok..then, i hope it will not work for me. Because i will get the attachement everytime as html file from server.

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10

Re: Will Attachment Handler work for Mail Client??

[ Edited ]

But currently i am able to do something with the attachmentHandler and AttachmentDownload Manager. First of all, my attachment is prefixed with x-rimdevice. So while i am clicking the menu option, i am downloading the attachment. After that, i am getting the path of that attachment and then using Browserfield, i am able to parse that html file. And now i after parsing, i am getting the data from the html files which i need. But the big issue is for this process: Time. It is taking a long process to this whole part(nearly 7-10 mins). I am sure there something wrong in my code. Can you please the below code:

 

 public boolean supports(String contentType)
	    {

	        boolean val;

	        if (contentType.toLowerCase().indexOf("htm") != -1)
	        {
	        	Logger.out("MyViewer", "It is Html file");
	            val = true;
	        }
	        	
	        else
	            val = false;

	        return val;
	    }

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

	    //Runs when the user selects the above defined menu item
	    private BrowserField    _browser;
	    public void run(Message message, SupportedAttachmentPart p)
	    {
	    	
	    	String data = null;
            if (message.getContent() instanceof Multipart) {
	    		Multipart multi = (Multipart) message.getContent();
	    		for (int i = 0; i < multi.getCount(); i++) {
	    			 BodyPart  bp = multi.getBodyPart(i);
	    			if ( (bp instanceof SupportedAttachmentPart) && (bp.hasMore())) {
	    				Logger.out("",i+"--------  Attachment has More:"+bp.hasMore());
	    				try {
	    					 adm = new AttachmentDownloadManager(); 
	    					 adm.download(bp, null, new DownloadProgressListener(){

								public void downloadCancelled(Object element) {
									
								}

								public void downloadCompleted(Object element) {
									BodyPart bpnew = (BodyPart) element;
									startParse(bpnew);
									
								}

								public void updateProgress(Object element, int current, int total) {
									
								}
	    						 
	    					 });
	    					 
	    					 
	    				} catch (Exception e) {
	    					// TODO Auto-generated catch block
	    					e.printStackTrace();
	    				}
	    			} 
	    		}
            }

	    }
		
		  private void startParse(BodyPart bp){
    	    	String path = adm.getDownloadedFileName(bp);
				String[] ids = {"aid", "username", "orgName", "keyVersion",
                        "epayload", "sendURL", "encdata"};
            	tableValues = new Hashtable();
            	Logger.out("startParse", "----------4");
            	for (int k = 0; k< ids.length; k++){
            		tableValues.put(ids[k], "");
            	}
				_browser = new BrowserField();
    	         _browser.addListener(new BrowserListener(path));
				  _browser.requestContent(path);
				     }
					 
					  private class BrowserListener extends BrowserFieldListener {
    	    	String path = null;
    	    	
    	    	public BrowserListener(String uri)
    	    	{
    	    		path = uri;
    	    		
    	    	}
    	        public void documentAborted(BrowserField field, Document document) {
    	            Logger.out("BrowserListener", "documentAborted");
    	            
    	        }
    	         
    	        public void documentCreated(BrowserField field, ScriptEngine engine, Document document) {
    	        	Logger.out("BrowserListener", "documentCreated");
    	        	document.setDocumentURI(path);
    	            
    	        }
    	         
    	        public void documentError(BrowserField field, Document document) {
    	        	Logger.out("BrowserListener", "documentError********************");
    	            
    	        }
    	         
    	        /**
    	         * The document is loaded so this is the time to fetch the data
    	         * that I want.
    	         *
    	         * @param field The BrowserField
    	         * @param document A w3c.dom.Document
    	         */
    	        public void documentLoaded(BrowserField field, Document document) {
    	        	
    	        	
    	        	
    	        	Logger.out("BrowserListener", "documentLoaded");
    	            try {
    	                NodeList list = document.getElementsByTagName("*");
    	                String key = null;
    	                for (int i = 0; i < list.getLength(); i++) {
    	                    Node node = list.item(i);
    	                    String nodeName = node.getNodeName();
    	                    Logger.out("BrowserListener", "META  :"+i+": "+nodeName);
    	                    if (nodeName.equalsIgnoreCase("input")){
    	                    	NamedNodeMap map = node.getAttributes();
    	                    	key = null;
    		                    for (int j = 0; j < map.getLength(); j++) {
    		                    	Logger.out("BrowserListener", "Attributes  :"+j+": "+map.item(j).getNodeName());
    		                    	String attribName = map.item(j).getNodeName();
    		                    	if (attribName.equalsIgnoreCase("id")){
    		                    		String attribVal = map.item(j).getNodeValue();
    		                    		if (tableValues.containsKey(attribVal)){
    		                    			key = attribVal;
    		                    			continue;
    		                    		}
    		                    	}
    		                    	if (attribName.equalsIgnoreCase("value") && (key != null) ){
    		                    		tableValues.put(key, map.item(j).getNodeValue());
    		                    	}
    		                    }
    	                    }
    	                    // Get the attributes
    	                    
    	                }
    	                for (Enumeration e = tableValues.keys() ; e.hasMoreElements() ;) {
//                            System.out.println(e.nextElement());
                        	String k = (String)e.nextElement();
                            Logger.out("ParserResult", "Key :"+k+", Value :"+tableValues.get(k));
                        }
    	            } catch (Exception e) {
    	            	Logger.out("BrowserListener", "Exception :"+e.toString());
    	                System.out.println(e.toString());
    	            }
    	        }
    	         
    	        public void documentUnloading(BrowserField field, Document document) {
    	        	Logger.out("BrowserListener", "documentUnloading");
    	        }
    	         
    	        public void downloadProgress(BrowserField field, ContentReadEvent event) {
    	        	Logger.out("BrowserListener", "downloadProgress");
    	        }
    	    }

}

  Sorry for this much big code..please help.. Thanks..

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10

Re: Will Attachment Handler work for Mail Client??

Actually in the downloadProgress() method. it is showing a long time..the log is printing for a long time..i am not getting what is the problem there??/

Please use plain text.