在模拟器上,此代码无错误或例外:
getContentResolver().delete(Uri.parse("content://sms/"), "body = ? and date = ?", new String[]{body,date)});
正确删除短信。
但是当我在galaxy s2上尝试这个时,我有一个sqliteexception没有这样的列。
我查了一下:
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));
}
如果列在那里并且情况确实如此,那么它们都存在。它应该像在模拟器上一样在星系s2上运行良好。我不知道这是否有效或在其他设备上是否相同。但这个例外是从哪里来的?
这是异常日志:
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 = ?))
这里是带有光标的“content:// sms”的返回列:
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
答案 0 :(得分:2)
我有同样的情况消息在模拟器上被删除,我的Htc Desire,Galaxy Mini,但在Galaxy S,Galaxy SL上抛出异常
这就是我现在所做的..将改进/更新我的答案..目前的实施工作正常
try
{
Uri deleteUri = Uri.parse("content://sms");
int i= getContentResolver().delete(deleteUri, "address=? and date=?", new String[] {Phone, Time});
Log.d("*****GE *********", Phone +" "+ Time + " ^^"+i);
}
catch(Exception ex)
{
Log.d("deleteEx", ex.toString());
Uri deleteUri = Uri.parse("content://sms");
int i= getContentResolver().delete(deleteUri, "address=? and date=?", new String[] {Phone, Time});
Log.d("*****GE *********", Phone +" "+ Time + " ^^"+i);
}
finally
{
finish();
overridePendingTransition(R.anim.nothing, R.anim.animout);}
我已将代码放入try catch ..我首先尝试它如果它抛出异常我在catch中做同样的事情并且它有效。 希望能帮助到你。 我不是专业人士..所以我不知道为什么会发生这种情况