Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to read sms from a particular date in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.18k
    Comment on it

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

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: