Using getContentResolver in BroadcastReceiver extended class

好久不见. 提交于 2019-12-10 16:08:28

问题


I have to use the getContentResolver method in a class that extends BroadcastReceiver and I found that getContentResolver can be used only in a class that extends Activity. I try to do a static method in a class that extends activity but i can't use getContentResolver in a static method. I also tried with a non-static method but when i run the appliaction I get an error. How can I do? Thanks!


回答1:


In your onReceive(Context, Intent) you receive a Context object which has a getContentResolver() Method.




回答2:


ContentResolver contentResolver =context.getContentResolver();
cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder);


来源:https://stackoverflow.com/questions/6074691/using-getcontentresolver-in-broadcastreceiver-extended-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!