如何获取android中特定日期之间发送的短信数量
有没有办法检索 Android 中特定日期之间发送的 SMS 消息的数量?
我更喜欢官方支持的 SDK 功能,在您的答案中说明这是否是官方 SDK 的一部分会有所帮助。
我知道这个堆栈溢出问题,但它似乎使用没有正式支持 android.provider.Telephony.SMS_RECEIVED
和 content://sms/sent
,所以我宁愿不使用它(如果我错了,请纠正我)这是不支持的)。
Is there a way to retrieve the number of sent SMS messages between specific dates in android?
I would prefer an officially supported SDK functionality, this stating in your answer whether this is part of the official SDK would be helpful.
I am aware of this stack overflow question but it seems to use the not officially supported android.provider.Telephony.SMS_RECEIVED
and content://sms/sent
, so I would rather not use it (please correct me if i'm wrong about this being unsupported).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这是一个非常老的问题,我刚刚遇到并发现没有答案。所以请不要仅仅因为这个就对我投反对票。也许有人需要这个答案。
您所要做的就是查询电话内容提供程序(我使用 CallLog.Calls 常量而不是列名称的硬编码字符串)
对于您的情况,您所要做的就是提供一个 where 子句,该子句将使选择投影。您需要以毫秒为单位转换您提到的日期范围(获取日期并将其转换为毫秒)。确保您的模式对应于
“dd-MM-yy”
。where 子句应如下所示:
这将我们带到查询的最终形式: SELECT date FROM sms_content WHERE date
SELECT date FROM sms_content WHERE date
SELECT date FROM sms_content WHERE date
'firstbound' AND 日期 < '第二个边界'
修改
Uri smsContentUri = Uri.parse("content://sms/");
添加到"content://sms/" 的末尾
已发送或收件箱获取“content://sms/sent”
或“content://sms/inbox”
,具体取决于您要查询的邮箱。干杯。
I know it is very old question, I just came across and spotted as unanswered. So please do not downvote me just because of it. Maybe someone will need this answer.
All you have to do is to query the phone content provider (I used
CallLog.Calls
constants instead hardcoded strings for columns names)For your case all you have to do is to supply a where clause which will make selection over the projection. You need to convert bounds of dates you've mentioned in miliseconds (get the date and convert it to ms). Make sure your pattern corresponds to
"dd-MM-yy"
.The where clause should look like:
which take us to the final form of our query:
SELECT date FROM sms_content WHERE date < 'firstbound' AND date < 'second bound'
Modify
Uri smsContentUri = Uri.parse("content://sms/");
adding to the end of the"content://sms/"
sent or inbox to get"content://sms/sent"
or"content://sms/inbox"
, regarding which box you want to query.Cheers.