Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect outgoing SMS messages in the backgound of an Android application?

How can I run an Android application in the background that counts the number of SMS messages sent and, in addition, determine the detail of each one?

like image 593
Asshwani Singh Avatar asked Nov 05 '22 14:11

Asshwani Singh


1 Answers

you can fetch sent msg:

    Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");
    Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
                new String[] { "_id", "thread_id", "address", "person", "date",
                                "body", "type" }, null, null, null);
    startManagingCursor(cursor1);
    String[] columns = new String[] { "address", "person", "date", "body","type" };
    if (cursor1.getCount() > 0) {
        String count = Integer.toString(cursor1.getCount());
        Log.e("Count",count);
        while (cursor1.moveToNext()){
            String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
            String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
            String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
            String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
            String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
        }
    }

you can use counter to retrive recently sent sms.

See other useful links:

Android: Is there any way to listen outgoing sms?

Listen outgoing SMS or sent box in Android

How to listen/subscribe to Outgoing SMS notifications?

like image 77
Vineet Shukla Avatar answered Nov 09 '22 10:11

Vineet Shukla