问题
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:
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.
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