getcontentresolver () is undefined for the type

。_饼干妹妹 提交于 2019-12-04 05:20:26
Arash GM

The problem is Context, pass context of your Activity which use your Class in it's Constructor :

Context context;
public ContactManager (Context context) {
    this.context = context;
}

then use

context.getContentResolver()

absolutely perfect the use of context here.

You can also simply use this:

 public class ContactManager  {

  public ArrayList<Product> getContactNumber(Context mContext) {
    Cursor phones = mContext.getContentResolver().query(
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
        null, null);
    while (phones.moveToNext()) {
    String name = phones
            .getString(phones
                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    String phoneNumber = phones
            .getString(phones
                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
   phones.close();}}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!