如何阅读一个月特定数量的消息android?

How to read particular number of one month messages android?

我想在特定时间阅读特定号码的消息。例如我想阅读“+91934345432”一个月前的消息。(例如今天8月6日所以我需要7月6日到8月6日之间的消息。)

我的代码:

Calendar c = Calendar.getInstance();

    long date2 = c.getTimeInMillis();

    c.add(Calendar.DAY_OF_YEAR, -30);

    long date1 = c.getTimeInMillis();
    Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
    Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, "datetime(date/1000, 'unixepoch') between " + date1 + " and " + date2 + " ", null, null);
    startManagingCursor(cursor1);

    String[] columns = new String[] { "address", "person", "date", "body","type" };
    if (cursor1.getCount() > 0) {
        String count = Integer.toString(cursor1.getCount());
        while (cursor1.moveToNext()){
            String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
            String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
            body = cursor1.getString(cursor1.getColumnIndex(columns[3]));
            String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
            String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
         //   System.out.println("Int Date : " + new Date(((long)Integer.parseInt(date))*1000L));
            if(address.contains("AD-AIRMTA")&& body.contains("Recharge")){


                Log.v("Tag_b0dy",""+body);



            }

        }
    }

结果: Tag_b0dy:null

提前致谢

您可以将选择添加到您的查询中:-[​​=14=]

Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, "datetime(date/1000, 'unixepoch') between date1 and date2", null, null);

date1 is 6th July in milliseconds and date2 is 6th august in milliseconds

要获取日期 1 和日期 2,您可以使用 java.util.Calendar 作为

Calendar c = Calendar.getInstance();

long date2 = c.getTimeInMillis();

c.add(Calendar.DAY_OF_YEAR, -30);

long date1 = c.getTimeInMillis();

所以最终查询将如下所示

Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, "datetime(date/1000, 'unixepoch') between " + date1 + " and " + date2 + ", null, null);
 Calendar c = Calendar.getInstance();

        date2 = c.getTimeInMillis();

        c.add(Calendar.DAY_OF_YEAR, -30);

  long  MonthAgo = c.getTimeInMillis();

 Uri  qryinBox = Uri.parse("content://sms/inbox");
        Cursor qryinBoxRes = getContentResolver().query(qryinBox, new String[]{"_id", "thread_id", "address", "person", "date", "body", "type"}, null, null, null);
        startManagingCursor(qryinBoxRes);

        String[]   columns = new String[] { "address", "person", "date", "body","type" };

        if (qryinBoxRes.getCount() > 0) {
            String count = Integer.toString(qryinBoxRes.getCount());
            while (qryinBoxRes.moveToNext()){
                String address = qryinBoxRes.getString(qryinBoxRes.getColumnIndex(columns[0]));
                long SMSdate = qryinBoxRes.getLong(qryinBoxRes.getColumnIndex(columns[2]));
                body = qryinBoxRes.getString(qryinBoxRes.getColumnIndex(columns[3]));
                String name = qryinBoxRes.getString(qryinBoxRes.getColumnIndex(columns[1]));
                String type = qryinBoxRes.getString(qryinBoxRes.getColumnIndex(columns[4]));
                if(address.contains("+9189245454489")&&SMSdate > MonthAgo){

// here u will get that one month msseges of particular number
}