根据我得到的较早答案,我在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);


...但是得到了错误信息,“对于类型KITSMSReceiver,未定义方法getContentResolver()”

最佳答案

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();  // <-----
    }
  }};

  // ...

}

10-04 14:09