-2

I have a ContentObserver for all SMS sent/received on the phone, and when an SMS is sent, this is the data I get from the cursor:

01-09 09:52:13.523: I/WOWOW(1830): _id: 213
01-09 09:52:13.523: I/WOWOW(1830): thread_id: 1
01-09 09:52:13.523: I/WOWOW(1830): address: null
01-09 09:52:13.523: I/WOWOW(1830): person: null
01-09 09:52:13.523: I/WOWOW(1830): date: 1326120733305
01-09 09:52:13.523: I/WOWOW(1830): date_sent: 0
01-09 09:52:13.523: I/WOWOW(1830): protocol: null
01-09 09:52:13.527: I/WOWOW(1830): read: 1
01-09 09:52:13.527: I/WOWOW(1830): status: -1
01-09 09:52:13.527: I/WOWOW(1830): type: 3
01-09 09:52:13.527: I/WOWOW(1830): reply_path_present: null
01-09 09:52:13.527: I/WOWOW(1830): subject: null
01-09 09:52:13.527: I/WOWOW(1830): body: Hello i am testing
01-09 09:52:13.527: I/WOWOW(1830): service_center: null
01-09 09:52:13.527: I/WOWOW(1830): locked: 0
01-09 09:52:13.527: I/WOWOW(1830): error_code: 0
01-09 09:52:13.527: I/WOWOW(1830): seen: 0

Now, from this data I can get the message of the SMS, the time it was sent, but I dont understand how i am going to get the recipient. Can somebody help me out here? Thanks!

Qasim
  • 1,686
  • 4
  • 27
  • 51

2 Answers2

1

This question was answered here a while back. (Copied for convenience).

"content://sms/" is not officially documented and it's realisation is up to device manufacturer. there is no clean way of retrieving any sms-related info.

Community
  • 1
  • 1
Chris Cashwell
  • 22,308
  • 13
  • 63
  • 94
  • How come it was downvoted? Because of a duplicate or? Because I think its a good question that involves digging deeper. What exactly is the thread ID? – Qasim Jan 09 '12 at 21:42
  • After doing some testing, thread_id is unique to every contact you send a message to. I will keep looking for a solution. – Qasim Jan 09 '12 at 21:45
  • after more tests I now realize that the "address" field is sometimes null, and most of the time actually contains an address. The address is the recipient of the SMS when you are sending an outgoing SMS from the phone. Now, I think this is because when an SMS is put into ://sms, it gets put in there multiple times for some odd reason, and maybe only the last one contains the correct information. I will do more tests, and this question will INDEED get an answer, you have my word. – Qasim Jan 09 '12 at 21:50
1

The solution to this, to any phone that does support content://sms, (not really sure which don't, but most do), is to check if "address" is not null, and if it isnt null, also check if the last checked "_id" of the message is different, because content://sms tends to give you the same message 3-4 times sometimes, and only one of them have "address" as a real value and not null. Here is my final code in my ContentObserver onChange:

Cursor cur = contentResolver.query(Uri.parse("content://sms"), null, null, null, null);
    cur.moveToNext();
    String id = cur.getString(cur.getColumnIndex("_id"));

    final String user_id = settings.getString("user_id", "0");

    if(!cur.getString(cur.getColumnIndex("address")).equals("null") && !id.equals(lastId)) {
        for(int i =0; i < cur.getColumnNames().length; i++) {
            Log.i("WOWOW", cur.getColumnName(i) + ": " + cur.getString(cur.getColumnIndex(cur.getColumnName(i))));
        }
        Log.i("WOWOW", "*****************************************************");
        lastId = id;
    }
Qasim
  • 1,686
  • 4
  • 27
  • 51