Keeping count of the number of SMS's sent in Android

↘锁芯ラ 提交于 2019-12-12 02:12:24

问题


I want to track the number of messages that are sent from an android phone. I'm aware that there is a Broadcast message whenever a SMS is received but there is no particular event for a sent message.

I don't wanna end up counting the number of messages that appear in the "sent" area cos if I delete a sent message, the count will get changed.


回答1:


Two possible solutions:

  1. You could read the sent messages folder on a schedule, and only count the messages with time stamps that were sent between the last time you checked and the current time you're checking.

  2. You could send the sms yourself (assuming the user is willing to go through your application to do it), then through your pending intent you could easily tell yourself when this was done.

Personally, I like possible solution #1, thought there is the problem that some SMS applications don't even store the sms in the default content provider: content://sms/sent, or like you said, the user might delete the message too quickly before it can even be counted that first time. Unfortunately, I don't think there is a better solution at this time than an hybrid solution of the two solutions I'm proposing, and even that one offers no guarantee that you won't miss some messages.




回答2:


You can handle this when you send message. Store the count in the shared preference. When SMS is sent, increment the value in the shared preference.



来源:https://stackoverflow.com/questions/5878910/keeping-count-of-the-number-of-smss-sent-in-android

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