Goran
Goran

Reputation: 1239

Reading text from SMS, and show it as text view

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 ??

Upvotes: 0

Views: 2801

Answers (2)

Joshua Abrams
Joshua Abrams

Reputation: 387

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)

Upvotes: 0

user874649
user874649

Reputation:

You can start here for handling received SMS.

Upvotes: 1

Related Questions