hanky
hanky

Reputation: 31

Android SMS programming

I want to find a way specific SMS that contains a specific word and answer back automatically.

I have found a way to answer the SMS but I still can't work on finding the SMS...

Upvotes: 3

Views: 2308

Answers (4)

techroid
techroid

Reputation: 477

In your broadcast receiver for incoming SMS, check the SMS body. If the SMS body contains that particular word then send a reply to that number. In the same way you can also check for incoming numbers.

Example to check for particular number:

if (smsBody.contentEquals("word to match")) {
   // create reply
}

Upvotes: 1

Evan Ginsberg
Evan Ginsberg

Reputation: 41

Its true that its not documented but people have been using this for years and if an update was to change the way we access the SMS database it would affect hundreds of users applications. So I doubt any time soon they would change this.

Anyway, start by creating a cursor object to the SMS database and just run a query with no conditions in the where clause. Then just run through the database pulling out the values you need. Someone was also nice enough to post the different column names in the database. Here they are: How many database columns associated with a SMS in android?

Below is a code snippet to get the SMS's from the database.

Cursor messages; 
    Columns message = ColumnsFactory.messages(); //points to structutre
    messages = getContentResolver().query(Uri.parse("content://sms/"),
            null, null, null, null);



    while (messages.moveToNext()) {
    //do stuff here.

Upvotes: 2

ludwigm
ludwigm

Reputation: 3383

There is an undocumented content provider for SMS: "content://sms/inbox" . But this is not official and can change. There is no proper way of sms access.

Upvotes: 0

Roger Hills
Roger Hills

Reputation: 361

Have you tried Google App Inventor? It has an example of this very type of app.

App inventor example website

Upvotes: 1

Related Questions