Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检索最近5天的收件箱邮件?_Java_Android - Fatal编程技术网

Java 如何检索最近5天的收件箱邮件?

Java 如何检索最近5天的收件箱邮件?,java,android,Java,Android,嗨,我能够检索所有收件箱的邮件,但我想检索的邮件只有过去5天如何实现这一点 private void readMessage(){ Uri inboxURI = Uri.parse("content://sms/inbox"); String[] reqCols = new String[] { "_id", "address", "body", "date" }; ContentResolver cr =

嗨,我能够检索所有收件箱的邮件,但我想检索的邮件只有过去5天如何实现这一点

        private void readMessage(){
            Uri inboxURI = Uri.parse("content://sms/inbox");
            String[] reqCols = new String[] { "_id", "address", "body", "date" };
            ContentResolver cr = getContentResolver();
            Cursor c = cr.query(inboxURI, reqCols, null, null, null);

        }

<uses-permission android:name="android.permission.READ_SMS">
private void readMessage(){
Uri inboxURI=Uri.parse(“content://sms/inbox");
String[]reqCols=新字符串[]{“\u id”,“address”,“body”,“date”};
ContentResolver cr=getContentResolver();
游标c=cr.query(inboxURI,reqCols,null,null);
}

您需要在“日期”列上使用where子句来检索日期大于5天前的所有数据。请检查下面的示例代码

private static final long FIVE_DAYS_MILIS = 24 * 5 * 60 * 60 * 1000;

    private void readMessage() {
        Uri inboxURI = Uri.parse("content://sms/inbox");
        long currentTimeMilis = System.currentTimeMillis();
        // Time milis before 5 days
        long milisBefore5Days = currentTimeMilis - FIVE_DAYS_MILIS;
        // Where clause saying that date should be greater that milis before 5
        // days.
        String selection = "date > ?";
        String selectionArgs[] = { Long.toString(milisBefore5Days) };
        String[] reqCols = new String[] { "_id", "address", "body", "date" };
        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(inboxURI, reqCols, selection, selectionArgs, null);
    }
希望这有帮助