run Generic Query on ContentResolver - Android android.content

Android examples for android.content:ContentResolver

Description

run Generic Query on ContentResolver

Demo Code


import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.Uri;
import android.os.Build;
import android.provider.CalendarContract;
import android.util.Log;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main{
    private static final String TAG = CalendarUtil.class.getSimpleName();
    private static void runGenericQuery(Context context, String queryName,
            Uri queryUri) {/* ww w . j  a v  a 2s .c om*/
        // Run query
        Cursor cursor;
        ContentResolver cr = context.getContentResolver();

        // Submit the query and get a Cursor object back.
        cursor = cr.query(queryUri, null, null, null, null);

        String cursorContent = DatabaseUtils.dumpCursorToString(cursor);

        if (cursor != null) {
            cursor.close();
        }

        Log.i(TAG, "------- " + queryName + " cursorContent: \n"
                + cursorContent);
    }
}

Related Tutorials