有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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

这是我的密码

    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;
}

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


共 (0) 个答案