on the emulator, this code works with no bugs or exceptions:
getContentResolver().delete(Uri.parse("content://sms/"), "body = ? and date = ?", new String[]{body,date)});
the sms is correctly deleted.
But when I try this on galaxy s2, I have an sqliteexception no such column.
I checked with :
Cursor columns = getContentResolver().query(Uri.parse("content://sms"), null,null,null,null);
for (int i=0;i<columns.getColumnCount();i++){
Log.i("name", columns.getColumnName(i));
}
if the columns were there and it was the case, they were all present. It should have worked ass well on the galaxy s2 like on the emulator. I don’t know if this works or is the same on other devices. but from where is this exception coming from?
here is the exception log :
02-07 20:44:32.364: E/AndroidRuntime(14658):
android.database.sqlite.SQLiteException: no such column: body: ,
while compiling: SELECT _id FROM threads WHERE _id IN (SELECT DISTINCT thread_id FROM
sms WHERE (body = ? and date = ?) UNION SELECT DISTINCT thread_id FROM wpm WHERE
(body = ? and date = ?) UNION SELECT DISTINCT thread_id FROM pdu WHERE ( locked = 1
AND body = ? and date = ?))
and here the returned columns for “content://sms” with cursor :
02-07 20:53:21.045: W/KeyCharacterMap(14961): No keyboard for id 0
02-07 20:53:21.060: W/KeyCharacterMap(14961): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-07 20:53:26.045: I/ApplicationPackageManager(14961): cscCountry is not German : FTM
02-07 20:53:26.320: I/name(14961): _id
02-07 20:53:26.320: I/name(14961): thread_id
02-07 20:53:26.320: I/name(14961): address
02-07 20:53:26.320: I/name(14961): person
02-07 20:53:26.320: I/name(14961): date
02-07 20:53:26.320: I/name(14961): protocol
02-07 20:53:26.320: I/name(14961): read
02-07 20:53:26.320: I/name(14961): status
02-07 20:53:26.320: I/name(14961): type
02-07 20:53:26.320: I/name(14961): reply_path_present
02-07 20:53:26.320: I/name(14961): subject
02-07 20:53:26.320: I/name(14961): body
02-07 20:53:26.320: I/name(14961): service_center
02-07 20:53:26.320: I/name(14961): locked
02-07 20:53:26.320: I/name(14961): error_code
02-07 20:53:26.320: I/name(14961): seen
02-07 20:53:26.325: I/name(14961): deletable
02-07 20:53:26.325: I/name(14961): hidden
02-07 20:53:26.325: I/name(14961): group_id
02-07 20:53:26.325: I/name(14961): group_type
02-07 20:53:26.325: I/name(14961): delivery_date
I am having the same scenario the Message gets deleted on emulator ,My Htc Desire,Galaxy Mini, But throws exception on Galaxy S,Galaxy SL
This is what I have done for now .. will Improve/update my answer ..as current implementation is working fine
I have put the code in try catch..I try it first Time if its throws exception i do the same in catch and it works.
Hope it helps.
I am not a pro .. so i do not know the reason why this is happening