about 9 years ago
You can create a method readSMS() as shown below where you can pass date and time to read the sms from that particular date.
- private void readSMS(String date, String time) {
- // Now create a SimpleDateFormat object.
- SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy'T'hh:mm:ss");
- String selectedDate = date+"T"+time;
- //For example: selectedDate="09-10-2015"+"T"+"00:00:00";
- // Now create a start time for this date in order to setup the filter.
- Date dateStart = null;
- try {
- dateStart = formatter.parse(selectedDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- // Now create the filter and query the messages.
- String filter = "date>=" + dateStart.getTime();
- final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
- Cursor cursor = getContentResolver().query(SMS_INBOX, null, filter, null, null);
- while (cursor.moveToNext()) {
- //perform the operation you want to
- }
- cursor.close();
- }
private void readSMS(String date, String time) { // Now create a SimpleDateFormat object. SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy'T'hh:mm:ss"); String selectedDate = date+"T"+time; //For example: selectedDate="09-10-2015"+"T"+"00:00:00"; // Now create a start time for this date in order to setup the filter. Date dateStart = null; try { dateStart = formatter.parse(selectedDate); } catch (ParseException e) { e.printStackTrace(); } // Now create the filter and query the messages. String filter = "date>=" + dateStart.getTime(); final Uri SMS_INBOX = Uri.parse("content://sms/inbox"); Cursor cursor = getContentResolver().query(SMS_INBOX, null, filter, null, null); while (cursor.moveToNext()) { //perform the operation you want to } cursor.close(); }
0 Comment(s)