gpt4 book ai didi

android - getcontentresolver() 未定义类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:56 24 4
gpt4 key购买 nike

我尝试获取所有联系人姓名和电话号码,我正在尝试使用 getContentResolver 但我正在获取

the method get content resolver () is undefined for the type

这个错误。

我该如何解决?

下面是代码:

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

最佳答案

问题是 Context,传递 Activity 的上下文,它在构造函数中使用了 Class:

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

然后使用

context.getContentResolver()

绝对完美地使用了这里的上下文。

关于android - getcontentresolver() 未定义类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18182426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com