query Context for cursor - Android android.database

Android examples for android.database:Cursor

Description

query Context for cursor

Demo Code

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

public class Main {

  public static Cursor query(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
      String sortOrder, int limit) {
    try {//from   w  ww . jav a2s.  c om
      ContentResolver resolver = context.getContentResolver();
      if (resolver == null) {
        return null;
      }
      if (limit > 0) {
        uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build();
      }
      return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
    } catch (UnsupportedOperationException ex) {
      return null;
    }
  }

  public static Cursor query(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
      String sortOrder) {
    return query(context, uri, projection, selection, selectionArgs, sortOrder, 0);
  }

}

Related Tutorials