title: Delete sms android after receiving With no delay
body: <p>I have some code to delete Android SMS messages programatically but when I try to delete it in onReceive then no SMS is deleted.</p>
  
  <p>Sample code to delete sms</p>
  
  <pre><code>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 &amp;&amp; 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) &amp;&amp; address.equals(number)) {
                  // mLogger.logInfo("Deleting SMS with id: " + threadId);
                  context.getContentResolver().delete(Uri.parse("content://sms/" + id), null, null);
              }
          } while (c.moveToNext());
      }
  } catch (Exception e) {
      // mLogger.logError("Could not delete SMS from inbox: " +
      // e.getMessage());
  }
  </code></pre>
  
  <p>When I paste this in <code>onReceived</code> then the new SMS is not deleted.</p>