2011-02-17 1 views
1

토스트 팝업과 함께 인쇄되는 안드로이드 앱을 가지고 있으며, tts로 수신 된 메시지를 읽습니다. "String origin = smsMessage [0] .getOriginatingAddress();"를 사용합니다. 발신자의 전화 번호를 알아내는 것.
전화에서 연락처 목록을 쿼리하려고합니다. 따라서 수신 번호가 연락처와 일치하면 &이 대신 발신자 이름을 읽습니다. 그렇지 않으면, 번호가 인식되지 않으면 기본값으로 원래 주소 번호를 읽는 &으로 인쇄됩니다. Iv'e는 How can I query Android contact based on a phone number?을 보았습니다.안드로이드 앱에서 연락 할 경기 번호

답변

1
Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(origin)); 
Cursor phonesCursor = context.getContentResolver().query(phoneUri, new String[] {PhoneLookup.DISPLAY_NAME}, null, null, null); 

if(phonesCursor != null && phonesCursor.moveToFirst()) { 
    displayName = phonesCursor.getString(0); // this is the contact name 
}//end if 

결국이 이동합니다.

-1

그 질문에 답이 있었고 코드를 게시했습니다.

Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, 
          Uri.encode(mNumber)); 
Cursor phonesCursor = managedQuery(phoneUri, new String[] {PhoneLookup.DISPLAY_NAME}, null, null, null); 
if(phonesCursor != null && phonesCursor.moveToFirst()) { 
    String displayName = phonesCursor.getString(0); // this is the contact name 
+0

시도해 보겠습니다. Robby. :) – GrumP

+0

managedQuery 행에 오류가 있습니다. 그걸로 뭘해야할지 잘 모르겠다. – GrumP

+0

@ GrumP 함수 호출에 추가로 'null'이 있습니다. 다시 시도하십시오. –