如何获取android中特定日期之间发送的短信数量

发布于 2024-10-03 09:36:08 字数 355 浏览 0 评论 0原文

有没有办法检索 Android 中特定日期之间发送的 SMS 消息的数量?

我更喜欢官方支持的 SDK 功能,在您的答案中说明这是否是官方 SDK 的一部分会有所帮助。

我知道这个堆栈溢出问题,但它似乎使用没有正式支持 android.provider.Telephony.SMS_RECEIVEDcontent://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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2024-10-10 09:36:08

我知道这是一个非常老的问题,我刚刚遇到并发现没有答案。所以请不要仅仅因为这个就对我投反对票。也许有人需要这个答案。

您所要做的就是查询电话内容提供程序(我使用 CallLog.Calls 常量而不是列名称的硬编码字符串)

 String[] projection = { CallLog.Calls.DATE };
 Uri smsContentUri = Uri.parse("content://sms/");
 Cursor cursor = this.getContentResolver().query(smsContentUri , selection,where, null, null);
 SimpleDateFormat format = new SimpleDateFormat("dd-MM-yy");
 cursor.moveToFirst();
  Log.d("SMS COUNT", ""+cursor.getCount()); 
  while(cursor.isAfterLast() == false){
        Log.d("SMS DATE", ""+cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE))); //raw format of the date in milliseconds
        long callDate = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));      
        String dateString = format.format(new Date(callDate));
        Log.i("SMS DATE",dateString);
        cursor.moveToNext();
 }

对于您的情况,您所要做的就是提供一个 where 子句,该子句将使选择投影。您需要以毫秒为单位转换您提到的日期范围(获取日期并将其转换为毫秒)。确保您的模式对应于“dd-MM-yy”

where 子句应如下所示:

String where = CallLog.Calls.DATE+"<"+FRIST_BOUND_IN_MS + " AND "+ CallLog.Calls.DATE + "< " + SECOND_BOUND_IN_MS;

这将我们带到查询的最终形式: 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)

 String[] projection = { CallLog.Calls.DATE };
 Uri smsContentUri = Uri.parse("content://sms/");
 Cursor cursor = this.getContentResolver().query(smsContentUri , selection,where, null, null);
 SimpleDateFormat format = new SimpleDateFormat("dd-MM-yy");
 cursor.moveToFirst();
  Log.d("SMS COUNT", ""+cursor.getCount()); 
  while(cursor.isAfterLast() == false){
        Log.d("SMS DATE", ""+cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE))); //raw format of the date in milliseconds
        long callDate = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));      
        String dateString = format.format(new Date(callDate));
        Log.i("SMS DATE",dateString);
        cursor.moveToNext();
 }

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:

String where = CallLog.Calls.DATE+"<"+FRIST_BOUND_IN_MS + " AND "+ CallLog.Calls.DATE + "< " + SECOND_BOUND_IN_MS;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文