2011-12-27 6 views
1

를 조회하려고, 나는 브로드 캐스트 리시버에서이 코드가 있습니다은 내가 가진 이전 답변에 따라 ContactList

Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(ASenderTel)); 
// Also tried; 
//ContentResolver cr = getContentResolver(); 
//Context c = this; 
Cursor c = getContentResolver().query(lookupUri, new String[] { PhoneLookup._ID }, null, null, null); 
return (c.getCount() > 0); 

을 ...하지만 ERR의 MSG를 얻을, "방법 getContentResolver()는 유형에 정의되지 않은 KITSMSReceiver "

+0

내가 사용하는 경우 :. 컨텐트 리졸버 CR = getContentResolver() 쿼리 (lookupUri, 새로운 String [] {PhoneLookup._ID} , null, null, null); 가 ... ERR에 MSG가 "있어서 getContentResolver()가 입력 KITSMSReceiver 대해 정의되지 않는다"된다 몹시 복잡 보인다 즉 –

답변

2

getContentResolver()는 android.content.Context 클래스의 메서드입니다. 예를 들어, 활동에서 액세스 할 수 있습니다. 이 활동 클래스 내부에 방송 수신기를 넣어 실현하려 :

빠른 초안 :

public class MyActivity extends Activity { 

    // ... 

    private BroadcastReceiver myReceiver = new BroadcastReceiver() { 
    public void onReceive(Context c, Intent i) { 
     MyActivity.this.recvBroadcast(i); // forward to your activity 
     MyActivity.this.getContentResolver(); // <----- 
    } 
    }}; 

    // ... 

} 
+0

(KITSMSReceiver는 브로드 캐스트 리시버이다); 그것이 정말로 "선호되는 방법"입니까? 그런 다음 Private BroadcastReceiver가 이벤트를 호출해야합니까? –

+0

사실 onReceive 메서드와 함께 제공되는 Context 매개 변수를 사용하여 BroadcastReceiver를 별도의 파일에 넣을 수 있습니다 – marcinj