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
New Contributor
garyyanyan
Posts: 9
Registered: ‎05-03-2010
My Device: 9700
My Carrier: Telus

Folder event MessageAdded not invoked on device but on simulator

Hi,

 

This code works perfectly on simulator .. but not on device...

I think the method was invoke on some part .. but not finished .. i checked eventlog .. nothing there even i changed to catch throwable...

 

public FSMessageListener() {

  try {

   ServiceBook sb = ServiceBook.getSB();
   ServiceRecord[] srs = sb.getRecords();


   for (int cnt = srs.length - 1; cnt >= 0; --cnt) {

    // identify the service record associated with a mail message
    // service via a CID of 'CMIME'
    if (srs[cnt].getCid().equals("CMIME")) {
     ServiceConfiguration sc = new ServiceConfiguration(srs[cnt]);
     Store _store = Session.getInstance(sc).getStore();

     Folder[] folders = _store.list();
     for( int foldercnt = folders.length - 1; foldercnt >= 0; --foldercnt) {
        Folder f = folders[foldercnt];
        recurse(f);
     }

     m_application_indicator.setApplicationIconValue();
     
    }
   }

  } catch (Exception e) {

  }
 }

 
 public void recurse(Folder f)
 {
    if ( f.getType() == Folder.INBOX )
    {
        f.addFolderListener(this);
    }
    Folder[] farray = f.list();
    for (int fcnt = farray.length - 1; fcnt >= 0; --fcnt)
    {
        recurse(farray[fcnt]);
    }
 }

 

 public void messagesAdded(FolderEvent e) {  
  Message _message = e.getMessage();
  Folder messageFolder = _message.getFolder();

  if (messageFolder.getType() == Folder.INBOX) {

   FSIssueObject _issue = new FSIssueObject(_message);
   
   if (_issue.IsIssue()) {
    m_business_layer.addIssueEmail(_issue);
    
    UiApplication.getUiApplication().invokeLater (new Runnable() {
        public void run()
        {
            //Perform screen changes here.

            //Calling invalidate() on your screen forces the paint
            //method to be called.
         m_application_indicator.setApplicationIconValue();
        }
    });
   }
  }
 }

 

In FSIssue object ... i try to open up the email .. is it taking too long ..so it dropped ?

 

 

 

public FSIssueObject(Message message) {
  String _subject = message.getSubject();
  if (_subject.equalsIgnoreCase("An automated issue has been assigned to you")) {
   m_date = message.getReceivedDate().getTime();
   findEmailBody(message.getContent());
   parseDetail(m_htmlMessage == "" ? m_plainTextMessage
     : m_htmlMessage);
  }
 }

 

private void findEmailBody(Object obj) {
  // Reset the attachment flags.
  m_hasSupportedAttachment = false;
  m_hasUnsupportedAttachment = false;

  if (obj instanceof Multipart) {
   Multipart mp = (Multipart) obj;

   // Extract all of the parts within the Multipart message.
   for (int count = 0; count < mp.getCount(); ++count) {
    findEmailBody(mp.getBodyPart(count));
   }
  } else if (obj instanceof TextBodyPart) {
   // This message only has a text body.
   TextBodyPart tbp = (TextBodyPart) obj;
   readEmailBody(tbp);
  } else if (obj instanceof MimeBodyPart) {
   MimeBodyPart mbp = (MimeBodyPart) obj;

   if (mbp.getContentType().indexOf(ContentType.TYPE_TEXT_HTML_STRING) != -1) {
    // The message has no attachments.
    // Read the email body, which may contain a TexBodyPart,
    // MimeBodyPart or both.
    readEmailBody(mbp);
   } else if (mbp.getContentType().equals(
     ContentType.TYPE_MULTIPART_MIXED_STRING)
     || mbp.getContentType().equals(
       ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING)) {
    // The message has attachments or we are at the top level of the
    // message. Dig deeper to find the body.
    // Extract all of the parts within the MimeBodyPart message.
    findEmailBody(mbp.getContent());
   }

  } else if (obj instanceof SupportedAttachmentPart) {
   // This is a supported attachment.
   m_hasSupportedAttachment = true;
  } else if (obj instanceof UnsupportedAttachmentPart) {
   // This is an unsupported attachment.
   m_hasUnsupportedAttachment = true;
  }
 }

 private void readEmailBody(TextBodyPart tbp) {
  // This is the plain text body.
  m_plainTextMessage = (String) tbp.getContent();

  // Determine if all of the text body part is present.
  if (tbp.hasMore() && !tbp.moreRequestSent()) {
   // It does, request more of the message.
   try {
    Transport.more((BodyPart) tbp, true);
   } catch (Throwable e) {
    e.printStackTrace();
   }
  }
 }

 // Displays the HTML or plain text body of the email message.
 private void readEmailBody(MimeBodyPart mbp) {
  // Extract the content of the message.
  Object obj = mbp.getContent();
  String mimeType = mbp.getContentType();
  String body = null;

  // Determine if the data returned is a String or a byte array.
  // If the BlackBerry is able to convert the HTML content into a String,
  // then a String should be returned. If the encoding is not supported a
  // byte array is returned to allow your application to work with the raw
  // data.
  if (obj instanceof String) {
   body = (String) obj;
  } else if (obj instanceof byte[]) {
   body = new String((byte[]) obj);
  }

  if (mimeType.indexOf(ContentType.TYPE_TEXT_PLAIN_STRING) != -1) {
   // This is the plain text body.
   m_plainTextMessage = body;

   // Determine if all of the text body part is present.
   if (mbp.hasMore() && !mbp.moreRequestSent()) {
    // It does, request more of the message.
    try {
     Transport.more((BodyPart) mbp, true);    
    } catch (Throwable e) {
     e.printStackTrace();
    }
   }
  } else if (mimeType.indexOf(ContentType.TYPE_TEXT_HTML_STRING) != -1) {
   // This is the HTML body part of the message.
   m_htmlMessage = body;

   // Determine if all of the HTML body part is present.
   if (mbp.hasMore() && !mbp.moreRequestSent()) {
    // It does, request more of the message.
    try {
     Transport.more((BodyPart) mbp, true);
     
    } catch (Throwable e) {
     e.printStackTrace();
    }
   }
  }
 }

 

Please use plain text.
New Contributor
garyyanyan
Posts: 9
Registered: ‎05-03-2010
My Device: 9700
My Carrier: Telus

Re: Folder event MessageAdded not invoked on device but on simulator

Anyone pls?

 

Looks like the process stopped or dropped when it request more data for the email ...

Transport.more((BodyPart) mbp, true);

Please use plain text.