sms 읽어오기 - 기간 설정
휴대전화에서 sms읽어 오는 소스
https://developer.android.com/guide/topics/providers/content-provider-basics.html?hl=ko
[Java] 자바 날짜 계산하는 다양한 방법, GregorianCalendar, SimpleDateFormat
http://mainia.tistory.com/2119
JAVA DATE 함수 사용. 날짜 계산하기
http://coronasdk.tistory.com/766
검색하면 잘 나와있다.
내가 하고자 하는 것은 6개월전부터의 sms내역을 읽어오고 싶었다.
전체 말고.
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//형식 지정
Date currentTime = new Date(); //현재 시간을 구한다.
String mTime = mSimpleDateFormat.format(currentTime); // 형식에 맞게 변환
Date before6Mon = addMonth(currentTime,-6); // 6개월전 날짜를 구한다.
long before6Mon_msec = before6Mon.getTime();//6개월전 날짜를 long형으로 변환
String[] str = {"_id", "thread_id", "address", "person", "date", "body", "protocol", "read", "status"
, "subject", "service_center", "locked", "error_code", "seen"};
String where = "date >= "+before6Mon_msec;
Uri allMessage = Uri.parse("content://sms");
ContentResolver cr = mContext.getContentResolver();
Cursor c = cr.query(allMessage, str, where, null, "date DESC");
+
public static Date addMonth(Date date , int months){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, months);
return cal.getTime();
}
6개월의 기준을 어떻게 잡을 것인지 등은 더 생각해 봐야 하지만
쿼리문에 where절을 추가하면 조건을 넣을 수 있다.