消息不会在Android中删除

时间:2017-05-26 09:29:48

标签: java android smsmanager

我正在尝试开发app,其中我的要求是从特定号码删除短信。传出和传入消息。 现在我编码接收短信如下。 代码运行正常,可以删除邮件,但邮件不会被删除。

这仅适用于传入消息。

还请告诉我如何删除外发邮件。

void deleteMessage(Context context){

    String no="55778866";
    try {

        Uri uriSms = Uri.parse("content://sms/inbox");
        Cursor c = context.getContentResolver().query(
                uriSms,
                new String[] { "_id", "thread_id", "address", "person",
                        "date", "body" }, "read=0", null, null);
        if (c != null && c.moveToFirst()) {
            do {
                long id = c.getLong(0);

                String address = c.getString(2);


                long threadId = c.getLong(1);
                String body = c.getString(5);
                String date = c.getString(3);
                Log.e("log>>>",
                        "0--->" + c.getString(0) + "1---->" + c.getString(1)
                                + "2---->" + c.getString(2) + "3--->"
                                + c.getString(3) + "4----->" + c.getString(4)
                                + "5---->" + c.getString(5));


                Log.e("log>>>", "date" + c.getString(0));

                ContentValues values = new ContentValues();
                values.put("read", true);
                getContentResolver().update(Uri.parse("content://sms/"),
                        values, "_id=" + id, null);

                Log.e("SMS Match >>>>","address >>>>"+address+" no. >>>>"+no+" match >>>> "+address.equals(no));

                if (address.equals(no)) {

                    try{
                        context.getContentResolver().delete(
                                Uri.parse("content://sms/" + id), "date=?",
                                new String[] { c.getString(4) });
                       Log.e("log>>>", "Delete success.........");
                       Toast.makeText(getApplicationContext(),"SMS Deleted",Toast.LENGTH_SHORT).show();

                    }catch (Exception e){
                        Log.e("DELETE >>>",e.getMessage());
                    }
                     }
            } while (c.moveToNext());
        }
    } catch (Exception e) {
        Log.e("log>>>", "ERROR "+e.toString());
    }

}

0 个答案:

没有答案