小编use*_*896的帖子

接收后删除sms android没有延迟

我有一些代码以编程方式删除Android SMS消息,但当我尝试在onReceive中删除它时,没有删除短信.

删除短信的示例代码

try {
    // mLogger.logInfo("Deleting SMS from inbox");
    Uri uriSms = Uri.parse("content://sms/inbox");
    Cursor c = context.getContentResolver().query(
        uriSms, new String[] { "_id", "thread_id", "address", "person",
        "date", "body" }, null, null, null);

    if (c != null && c.moveToFirst()) {
        do {
            long id = c.getLong(0);
            long threadId = c.getLong(1);
            String address = c.getString(2);
            String body = c.getString(5);

            if (message.equals(body) && address.equals(number)) {
                // mLogger.logInfo("Deleting SMS with id: " + threadId);
                context.getContentResolver().delete(Uri.parse("content://sms/" + id), null, null);
            }
        } while (c.moveToNext());
    } …
Run Code Online (Sandbox Code Playgroud)

sms android

7
推荐指数
1
解决办法
2978
查看次数

标签 统计

android ×1

sms ×1