2012-03-15 11 views
1

날짜 이후에받은 모든 SMS를 읽으려고합니다.날짜 이후에 SMS 수신

Uri SMS_CONTENT_URI = Uri.parse("content://sms"); 
Uri SMS_INBOX_CONTENT_URI = Uri.withAppendedPath(SMS_CONTENT_URI, "inbox"); 

Cursor cursor = context.getContentResolver().query(SMS_INBOX_CONTENT_URI, new String[] { "_id" }, "date>=61291393200000", null, null); 
//61291393200000 = 03/01/12 

이 나에게 빈 커서를 반환 여기

는 코드입니다.

는이 코드를 실행 한 경우 :
Cursor cursor = context.getContentResolver().query(SMS_INBOX_CONTENT_URI, new String[] { "_id" }, "read=1", null, null); 

나에게 모든 SMS를 반환했다.

누군가가 sms를 날짜별로 필터링하는 방법을 알고 있습니까?

나는 send sms에서도 실행을 시도했지만 동일한 문제가 있었다.

답변

7

특정 날짜 이후에 다음 코드를 사용하여 SMS 메시지를 검색합니다.

// First select the date shown by the datepicker. 
// Here I am assuming that a DatePicker object is already created with id dpResult 
// to select a particular date. 
DatePicker datePicker = (DatePicker) findViewById(R.id.dpResult); 


// Now create a SimpleDateFormat object.   
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 

// Add 1 in month as its 0 based indexing in datePicker but not in SimpleDateFormat 
String selectedDate = datePicker.getYear() + "-" + (datePicker.getMonth() + 1) + "-" + datePicker.getDayOfMonth(); 

// Now create a start time for this date in order to setup the filter. 
Date dateStart = formatter.parse(selectedDate + "T00:00:00"); 

// 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 required stuff here.    
} 
cursor.close(); 

있어 http://realembed.blogspot.com/2013/11/retrieve-sms-message-on-particular-date.html

+0

나는 그 프로젝트를 더 이상 사용하지 않지만 코드는 나에게 좋아 보인다. 나는 그 대답을 받아 들였다. – jonathanrz

1

"date> = '61291393200000'"을 시도 했습니까?

숫자 값을 나타내는 SQL 문에는 'xxx'가 필요합니다.

+0

에서 코드 조각 이상 근무하지 않습니다 : /합니다. 하지만 고마워요. – jonathanrz