Android: Detect SMS Outgoing, Incorrect Count

孤者浪人 提交于 2019-12-01 04:00:41

Note that, when you send a SMS message, it will save the status of message. To solve it, you check the type of that records int type = c.getInt(c.getColumnIndex("type")); 3 times onchange():
1st : type = 6
2nd : type = 4
3rd : type = 2 (success)
then you can increase your counter.
This case is applied for 1 recipient only.
If there are much more 1 recipient, need to requery "thread_id" and "seen" to get the type. You can check how many message are sent success.
Good luck!

I found a solution to my problem. SMSs and MMSs can be uniquely distinguished by their _id value.

Uri uriSMSURI = Uri.parse("content://sms");
    Cursor cur = getContentResolver().query(uriSMSURI, null, null,
                 null, null);
    cur.moveToNext();
String id = cur.getString(cur.getColumnIndex("_id"));

How can I uniquely distinguish an outgoing SMS message and get an accurate count of the number of SMS messages sent?

You can't.

This content provider is not part of the Android SDK. Its use is undocumented and unsupported. Moreover, how any given messaging client (e.g., the AOSP Messenger app) might use it is itself undocumented and unsupported. A single sent SMS could result in 1,337 changes to the content provider, and you have no way to know. Furthermore, there is no requirement for outgoing SMS messages to even be recorded in this or any content provider. And, if recent behavior is any indication, it is possible that Google will shut down third-party access to this content provider in the future.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!