如何删除Android中SMS收件箱中的所有邮件?

use*_*267 1 android

我想删除我的消息中的所有消息,只需单击按钮.但我已经尝试过下面的编码,它不起作用......有人可以帮助我实现这个目标吗?谢谢...

public class DeleteSMSActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
Button press;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    press = (Button)findViewById(R.id.button1);
    press.setOnClickListener(this);
}

public void onClick(View view){

    ContentResolver cr = getContentResolver();
    Uri inboxUri = Uri.parse("content://sms/inbox");
    Cursor c = cr.query(inboxUri , null, null, null, null);
    while (c.moveToNext()) {
        // Delete the SMS
        String pid = c.getString(0); // Get id;
        String uri = "content://sms/" + pid;
        cr.delete(Uri.parse(uri), null, null);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

我应该在Manifest中添加什么?使用我的Galaxy Tab 2进行测试时关闭力

S.D*_*.D. 7

尝试删除_id:

Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://sms/"), 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();
    }
Run Code Online (Sandbox Code Playgroud)