Search code examples
androidcalllogandroid-cursor

How to use Cursor's in non Activity Classes


I wan't to get data's from CallLog.Calls.CONTENT_URI in non Activity classes. Am using cursor to get these data's from CallLog. But in non activity class cursor shows some error so how i can how i can do this?

Presently am doing like this,

public class CallReceiver extends Activity {
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);     
    Cursor cursor =  managedQuery(android.provider.CallLog.Calls.CONTENT_URI,null,null,null,null);
 startManagingCursor(cursor);

Solution

  • Cursor c = context.getContentResolver().query(uri, projection, selection, null, sortOrder);
        if (c.moveToFirst()) {
            ...
        }
        c.close();