Java 检索短信发送时间和接收时间

Java 检索短信发送时间和接收时间,java,android,sms,Java,Android,Sms,所以我想检索短信的发送和接收时间。当我们发送短信时,接收者会立即收到。但是,有时会出现提供商或网络错误,因此接收方将在其提供商/网络良好时收到该错误。我想做的是区分时间发送(发送方发送时)和时间接收(接收方接收时)。有什么办法吗 这是我的密码 public ArrayList<String> getSMS(){ ArrayList<String> sms = new ArrayList<>(); Uri uriSMSURI = Uri.

所以我想检索短信的发送和接收时间。当我们发送短信时,接收者会立即收到。但是,有时会出现提供商或网络错误,因此接收方将在其提供商/网络良好时收到该错误。我想做的是区分时间发送(发送方发送时)和时间接收(接收方接收时)。有什么办法吗

这是我的密码

    public ArrayList<String> getSMS(){
    ArrayList<String> sms = new ArrayList<>();
    Uri uriSMSURI = Uri.parse("content://sms/inbox");
    Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);

    while (cur != null && cur.moveToNext()) {
        String address = cur.getString(cur.getColumnIndex("address"));
        String body = cur.getString(cur.getColumnIndexOrThrow("body"));
        String date = cur.getString(cur.getColumnIndexOrThrow("date"));
        long milliSeconds = Long.parseLong(date);
        DateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy");
        DateFormat timeFormatter = new SimpleDateFormat("hh:mm aaa");
        DateFormat timeFormatterTwo = new SimpleDateFormat("HH:mm");
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(milliSeconds);
        String finalDateString = formatter.format(calendar.getTime());
        timeOne = timeFormatter.format(calendar.getTime());
        timeTwo = timeFormatterTwo.format(calendar.getTime());
        isTime = false;
        titleArrays.add(new ItemProperty("From: "+address, finalDateString, timeOne, body));
    }

    if (cur != null) {
        cur.close();
    }
    return sms;
}
public ArrayList getSMS(){
ArrayList sms=新的ArrayList();
Uri Uri=Uri.parse(“content://sms/inbox");
Cursor cur=getContentResolver().query(urimsuri,null,null,null);
while(cur!=null&&cur.moveToNext(){
字符串地址=cur.getString(cur.getColumnIndex(“地址”);
String body=cur.getString(cur.getColumnIndexOrThrow(“body”);
字符串日期=cur.getString(cur.getColumnIndexOrThrow(“日期”);
长毫秒=long.parseLong(日期);
DateFormat格式化程序=新的SimpleDateFormat(“EEE,d MMM yyyy”);
DateFormat timeFormatter=新的SimpleDateFormat(“hh:mm aaa”);
DateFormat timeFormatterTwo=新的SimpleDateFormat(“HH:mm”);
日历=Calendar.getInstance();
calendar.setTimeInMillis(毫秒);
String finalDateString=formatter.format(calendar.getTime());
timeOne=timeFormatter.format(calendar.getTime());
timeTwo=timeFormatterTwo.format(calendar.getTime());
isTime=false;
add(newitemproperty(“From:”+地址,finalDateString,timeOne,body));
}
如果(cur!=null){
cur.close();
}
回复短信;
}

如果你们知道我该怎么做,告诉我。谢谢

您想要这些信息的目的是什么?用户正在发送的?他们收到的那些?都是吗?在任何情况下,答案都可能是:不是真的,不管怎样,没有任何真正的准确性。对于已发送的邮件,这将需要一个传递报告。并非所有运营商都提供交付报告,而且这些报告的接收时间也不会记录在提供商中,因此,您只能对应用程序直接发送的邮件执行此操作。尽管如此,“已送达”的含义各不相同,并不一定意味着消息已经到达设备。对于接收到的消息,有到达设备的(近似)时间的
日期
列,还有
发送日期
列,但这实际上是服务中心的时间戳,不是它离开发送者设备的时间。如果你的应用程序在另一台设备上向自己发送精心编制的消息,你可以做得更好,但是对于任何给定的任意消息,这都不是什么好事。你想要这些消息是为了哪些?用户正在发送的?他们收到的那些?都是吗?在任何情况下,答案都可能是:不是真的,不管怎样,没有任何真正的准确性。对于已发送的邮件,这将需要一个传递报告。并非所有运营商都提供交付报告,而且这些报告的接收时间也不会记录在提供商中,因此,您只能对应用程序直接发送的邮件执行此操作。尽管如此,“已送达”的含义各不相同,并不一定意味着消息已经到达设备。对于接收到的消息,有到达设备的(近似)时间的
日期
列,还有
发送日期
列,但这实际上是服务中心的时间戳,不是它离开发送者设备的时间。如果你的应用程序在另一台设备上向自己发送精心编制的消息,你可以做得更好,但对于任何给定的任意消息,这都不是什么好事。