getcontentresolver()是未定义的类型 [英] getcontentresolver () is undefined for the type
本文介绍了getcontentresolver()是未定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让所有的联系人姓名和电话号码,我试图用 getContentResolver
但我正在逐渐
I try to get all contact names and number and i'm trying to use getContentResolver
but i am getting
该方法获取内容解析()是未定义的类型
the method get content resolver () is undefined for the type
此错误。
我怎样才能解决这个问题?
How can i fix it ?
下面是code如下:
public class ContactManager {
public ArrayList<Product> getContactNumber() {
Cursor phones = 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();
}
}
推荐答案
现在的问题是上下文
,通过你的活动的背景下
它使用它你的类
的构造函数:
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;
}
然后用
context.getContentResolver()
context.getContentResolver()
绝对完美的使用环境在这里。
absolutely perfect the use of context here.
这篇关于getcontentresolver()是未定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文