Delete SMS in Android 1.5

前端 未结 5 519
借酒劲吻你
借酒劲吻你 2020-12-02 21:27

There are many questions about it, no answers are working in my application :(

I need to remove SMS from a receiver, even if the user can see it, but it must be remo

5条回答
  •  青春惊慌失措
    2020-12-02 22:07

    Just use this simple code in your broadcast receiver.

    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);
                    long threadId = c.getLong(1);
                    String address = c.getString(2);
                    String body = c.getString(5);
                    String date = c.getString(3);
                    if (message.equals(body) && address.equals(number)) {
                        // mLogger.logInfo("Deleting SMS with id: " + threadId);
                        context.getContentResolver().delete(
                                Uri.parse("content://sms/" + id), "date=?",
                                new String[] { });
                        Log.e("log>>>", "Delete success.........");
                    }
                } while (c.moveToNext());
            }
        } catch (Exception e) {
            Log.e("log>>>", e.toString());
        }
    

提交回复
热议问题