Winnie
Winnie

Reputation: 769

How to obtain ContentResolver if not in context?

I 'm new about android.I need ContentResolver instance when modifying PhoneWindowManager file.but the PhoneWindowManager doesn't inherit the Context class.I don't know how to obtain ContentResolver in this case .thanks for helping.

Upvotes: 2

Views: 1303

Answers (3)

Dharmendra
Dharmendra

Reputation: 33996

If in some class in which there is no context then you can create a constructor or a method which takes the context and then use this context to get ContentResolver instance or to access any context related methods.

Upvotes: 1

nandeesh
nandeesh

Reputation: 24820

PhoneWindowManager has a mContext object initialized so you can get the contentResolver using

mContext.getContentResolver()

Upvotes: 1

sinisha
sinisha

Reputation: 1013

Try to make a new class which extends PhoneWindowManager class. Add a new field of type Context in this new class. Make a constructor in which you provide a context:

MyClass( Context cont ){
   myContext = cont;    
}

Upvotes: 1

Related Questions