问题
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