试图查询ContactList

时间:2011-12-27 00:24:31

标签: android android-contacts

基于我之前得到的答案,我在BroadcastReceiver中有这段代码:

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);

...但是得到错误信息,"方法getContentResolver()未定义类型KITSMSReceiver"

1 个答案:

答案 0 :(得分: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();  // <-----
    }
  }};

  // ...

}