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.23k
    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.

    1. private void readSMS(String date, String time) {
    2. // Now create a SimpleDateFormat object.
    3. SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy'T'hh:mm:ss");
    4. String selectedDate = date+"T"+time;
    5. //For example: selectedDate="09-10-2015"+"T"+"00:00:00";
    6. // Now create a start time for this date in order to setup the filter.
    7. Date dateStart = null;
    8. try {
    9. dateStart = formatter.parse(selectedDate);
    10. } catch (ParseException e) {
    11. e.printStackTrace();
    12. }
    13.  
    14. // Now create the filter and query the messages.
    15. String filter = "date>=" + dateStart.getTime();
    16. final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
    17. Cursor cursor = getContentResolver().query(SMS_INBOX, null, filter, null, null);
    18.  
    19. while (cursor.moveToNext()) {
    20. //perform the operation you want to
    21. }
    22. cursor.close();
    23. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: