Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Detect SMS Outgoing, Incorrect Count
    primarykey
    data
    text
    <p>I am trying to make an application to count the number of outgoing SMS messages from a phone. Presently I have the following code:</p> <pre><code>private void listenForSMS(){ Log.v("SMSTEST", "STARTED LISTENING FOR SMS OUTGOING"); Handler handle = new Handler(){}; SMSObserver myObserver = new SMSObserver(handle); ContentResolver contentResolver = getContentResolver(); contentResolver.registerContentObserver(Uri.parse("content://sms"),true, myObserver); } private class SMSObserver extends ContentObserver{ int count = 0; String lastMessage = null; public SMSObserver(Handler handler) { super(handler); } public void onChange(boolean selfChange) { super.onChange(selfChange); Log.v("SMSTEST", "HIT ON CHANGE"); Uri uriSMSURI = Uri.parse("content://sms"); Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null); cur.moveToNext(); String protocol = cur.getString(cur.getColumnIndex("protocol")); if(protocol == null){ count++; Log.v("SMSTEST", "SMS SENT: count: " + count); String content = cur.getString(cur.getColumnIndex("body")); }else{ Log.v("SMSTEST", "SMS RECIEVED"); } } } </code></pre> <p>When I send a one page SMS message, <code>onChange</code> is called 3 times. When I send a two page SMS message, <code>onChange</code> is called 4 times. 3 page message, called 5 times; And so on.</p> <p>NOTE: I have tried other variations of <code>Uri.parse("content://sms")</code>, such as "content://sms/sent", and nothing other than "content://sms" has gotten <code>onChange</code> to be called.</p> <p>How can I uniquely distinguish an outgoing SMS message and get an accurate count of the number of SMS messages sent?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload