Question

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!

Was it helpful?

Solution 2

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;
    }

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top