I
I
int02h2012-01-13 13:56:06
Java
int02h, 2012-01-13 13:56:06

Programming for Android. Interception of incoming SMS

Hello, dear Habra community! I recently decided to try my hand at programming for Android. I am writing an application, the essence of which is that it intercepts all incoming messages and if any message satisfies certain conditions, then it is immediately deleted.

After intercepting the message, I have an instance of SmsMessage. I am trying to remove it like this:

Uri deleteUri = Uri.parse("content://sms");
context.getContentResolver().delete(
  deleteUri,
  "address=? and date=?",
  new String[] {sms.getOriginatingAddress(), String.valueOf(sms.getTimestampMillis())});

After performing these steps, the SMS message remains in the Inbox folder.

I decided to view my entire inbox like this:
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(uriSms, null,null,null,null);
while (c.moveToNext())
{
  String body = c.getString(c.getColumnIndex("body"));
  long data = c.getLong(c.getColumnIndex("date"));
  String address = c.getString(c.getColumnIndex("address"));
}
c.close();

It turns out that data and sms.getTimestampMillis() differ by about 200 milliseconds. That is, the where condition in the delete query is not met.

Maybe I'm doing something wrong? I ask for your help.

UPD : Maybe somehow it is possible to process incoming SMS before the system itself, so that the user does not even see the notification?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anmipo, 2012-01-13
@int02h

stackoverflow.com/questions/6979540/how-can-i-intercept-an-incoming-sms-with-a-specific-text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question