Search code examples
androidtextsmsinbox

Retrieve messages from Inbox


I am making an App with the help of which I can get an ArrayList of all the Text messages. I had no problem for achieving that but when I am sending it to default SMS application of Android device, I see the text surrounding by "[]". But I don't want that brackets.

For Eg.: My Inbox has a text "Hello World", but I am getting string displaying "[Hello World]". I want the exact message that is being displayed in my Inbox. So what should i do to remove extra "[]" from my string.

Please help me on that. Thanks in advance


Solution

  • If you are trying to send the whole ArrayList with toString() and it's displaying the brackets you can try to rebuild the string:

    String message = "";
        for(int i=0; i<array.size(); i++){
            message += array.get(i) + ", ";
        }
    

    Where ", " can be your delimiter. But I'm not sure this is what you want, can you provide more info in the description?

    EDIT: Try

    String message="[Hello World]";
            message.substring(1,message.length()-1);