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
Contributor
Posts: 30
Registered: ‎04-25-2011
My Device: 9800
My Carrier: GSM

Need help to access message box

Dear All,

 

I am developing an application where i need to access the device Message Box to read SMS messages and store them in SDCard, or delete selected messages from message box.

 

Please guide me with some sample examples as i am new to this.

 

Also i need to access the MMS in the same way.

 

Regards

Bijay

Developer
Posts: 16,787
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Need help to access message box

there is no API to access SMS messages.
you can only listen to incoming or outgoing SMS, no way to access stored ones.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 30
Registered: ‎04-25-2011
My Device: 9800
My Carrier: GSM

Re: Need help to access message box

Hello Simon,

 

Thanks for your reply on the issue. But i have found some code from the forum on how to access the message inbox.

 

Please give your views about the code below:

 

    /**
     * Reading Message from Inbox
     */
    private void getMessageBox()
    {
        Folder store = null;
        // TODO Auto-generated method stub
        try
        {
            //Store mStore = Session.getDefaultInstance().getStore();
            Store mStore = Session.waitForDefaultSession().getStore();  // Here the app hangs up without any error
            Folder[] folders = mStore.list(Folder.INBOX);

            for(int i = 0; i<folders.length; i++)
            {
                String temp = folders[i].getFullName();
                temp = temp + i;
            }
            
            Folder inbox = folders[0];

            Message[] msgs = inbox.getMessages();
            Message inMsg = msgs[0];    // retrieve the first message
            
            Address[] recipients = inMsg.getRecipients(Message.RecipientType.TO);
            Date sent = inMsg.getSentDate();
            Address from = inMsg.getFrom();
            String subject = inMsg.getSubject();
            String txt = inMsg.getBodyText();
            Object o = inMsg.getContent();
            
            //verify that the message is not multipart
            if ( o instanceof String )
            {
                String body = (String)o;
            }           
            
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            Dialog.alert(e.toString());
            
            e.printStackTrace();
        }

 

 

Please help on the issue.

 

Regards

Bijay

Developer
Posts: 16,787
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Need help to access message box

the code is for mails
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter