0

I am trying to create app, that will get the text from SMS, and use it in textview. So something like this, message is recived, i check if it is message I want, then i extract text, save it to string, and then show this string in textview. Any suggestions from where should i start, any examples plese ??

Goran
  • 1,239
  • 4
  • 23
  • 36

2 Answers2

1

You can start here for handling received SMS.

  • Thank you very much, this is exactly what I need :) I do have another question, i don't want to display every message, i just want to display certain messages. So when I get SMS text to string, can I check if first word matches to the word I need, and thet display message ?? – Goran Sep 11 '11 at 10:51
  • 2
    You can compare the SMS string with the word you need, if true display message via Toast or in a textview, if false do nothing. This is a matter of Java, if you compare the whole string or just the first word...etc. –  Sep 11 '11 at 16:07
  • Can you write a sample of this ?? please. – Goran Sep 11 '11 at 18:51
  • This is java, you can ask another question with a #java tag or just search on google, I can't write the whole code here. –  Sep 12 '11 at 05:58
0

First I would listen for SMS incoming, and on incoming SMS show a notification. Then if the user opens your app, update your display using this to get the data you want:

Uri allMessage = Uri.parse("content://sms/inbox");
            ContentResolver cr = getContentResolver();
            Cursor c = cr.query(allMessage, null, null, null, null);

            //shows one message
            c.moveToNext();
            //uncomment to cycle thru ALL messages... This will take AWHILE
            //while (c.moveToNext()) {
                for(int i = 0; i != c.getColumnCount(); i++){


    String columnName = c.getColumnName(i);
                String columnValue = c.getString(i);

                Log.v(TAG, "Col: " + columnName);
                Log.v(TAG, "Val: " + columnValue);
            }

        //}

Play around with it a little. It Should have all of the data you need (distinguish SMSs by timestamp)

Joshua Abrams
  • 377
  • 1
  • 5
  • 17