android – getcontentresolver()未定义类型

android – getcontentresolver()未定义类型,第1张

概述我尝试获取所有联系人姓名和号码,我正在尝试使用getContentResolver,但我得到了 the method get content resolver () is undefined for the type 这个错误. 我该如何解决? 以下是代码: public class ContactManager {public ArrayList<Product> getContactNu 我尝试获取所有联系人姓名和号码,我正在尝试使用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);    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()未定义类型全部内容,希望文章能够帮你解决android – getcontentresolver()未定义类型所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1141066.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存