0

不知道为什么获取 Illgal 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();
    }
}
4

2 回答 2

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();
    }
于 2013-05-08T01:34:30.770 回答
0

我认为 LIKE 只能与 String 一起使用

Toast.makeText(this, getContentResolver().delete(u, "_id = ?", 
                    new String[]{"2"})+"", Toast.LENGTH_LONG).show();
于 2013-05-08T01:21:16.733 回答