마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

특정 전화번호에 대해서 SMS 목록 불러오기

0 추천
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Uri.parse("content://sms/inbox"),null,null,null,null);

int nameidx = cursor.getColumnIndex("address");
int dateidx = cursor.getColumnIndex("date");
int bodyidx = cursor.getColumnIndex("body");

StringBuilder result = new StringBuilder();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd HH:mm");

result.append("총 문자갯수 : " +getCount()+ "개\n");
int count = 0;
while (cursor.moveToNext()) {

    String name = cursor.getString(nameidx);
    long date = cursor.getLong(dateidx);
    String sdate = formatter.format(new Date(date));
    String body = cursor.getString(bodyidx);


        // 날짜
    result.append(sdate + ": \n");
    result.append("name" + "");
        // 내용
    result.append(body + "\n");

        // 최대 100까지만
    if (count++ == 100) {
        break;
    }

}
cursor.close();

TextView txtResult =(TextView)findViewById(R.id.SMS);
txtResult.setText(result);
 
여기서 01011112222 라는 번호에서 온 문자메세지만 TextView 에 표시하고 싶으면 어떻게 해야하나요?ㅠㅠㅠ if(cursor.getString(nameidx)=="01011112222")는 안되네요... 부탁드립니다
송사리맨 (120 포인트) 님이 2016년 11월 14일 질문

1개의 답변

0 추천
ContentResolver의 query 함수의 3, 4번쨰 파라미터에 where절을 추가하시면 됩니다.

3번쨰 "address=?"

4번째 new String[]{"01011112222"}

이렇게요.
Development Guy (70,570 포인트) 님이 2016년 11월 14일 답변
...