不知道为什么获取Illegal Argument Exception会导致android代码崩溃。 任何帮助将不胜感激....
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv=(TextView)findViewById(R.id.test_id); tv.append("\n");
Uri u=Uri.parse("content://sms/inbox");
try{
Toast.makeText(this, getContentResolver().delete(u, "_id like ?", new String[]{"2"})+"", Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:1)
删除uri是“content:// sms /”+ id;
Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null,null);
try {
while (c.moveToNext()) {
int id = c.getInt(0);
getApplicationContext().getContentResolver().delete(Uri.parse("content://sms/" + id), null, null);
}
}catch(Exception e){
Log.e(this.toString(),"Error deleting sms",e);
}finally {
c.close();
}
答案 1 :(得分:0)
我认为LIKE只能与String
一起使用Toast.makeText(this, getContentResolver().delete(u, "_id = ?",
new String[]{"2"})+"", Toast.LENGTH_LONG).show();