Example usage for android.database Cursor close

List of usage examples for android.database Cursor close

Introduction

In this page you can find the example usage for android.database Cursor close.

Prototype

void close();

Source Link

Document

Closes the Cursor, releasing all of its resources and making it completely invalid.

Usage

From source file:Main.java

public static String convertMediaUriToPath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from  ww  w .j  a va  2s.  c o  m
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}

From source file:Main.java

private static List<String> getTableColumns(final SQLiteDatabase database, final String tableName) {
    List<String> ret = null;
    try {//from  w w w . jav  a2  s .co  m
        final Cursor cur = database.rawQuery("SELECT * FROM " + tableName + " LIMIT 1", null);
        if (cur != null) {
            ret = new ArrayList<String>(Arrays.asList(cur.getColumnNames()));
        }
        cur.close();
    } catch (final Exception exception) {
        exception.printStackTrace();
    }
    return ret;
}

From source file:Main.java

public static boolean isPhoneNumberInContactList(Context context, String phoneNumber) {

    Cursor c = context.getContentResolver().query(Phone.CONTENT_URI, new String[] { Phone.DATA4 },
            Phone.DATA4 + " = ? or " + Phone.DATA1 + " = ?", new String[] { phoneNumber, phoneNumber }, null);

    boolean result = c.moveToFirst();
    c.close();

    return result;
}

From source file:Main.java

public static boolean isExist(SQLiteDatabase db, String pageId, String lang) throws SQLException {
    boolean itemExist = false;

    Cursor c = db.query(TABLE_CONTENT_HELP, null, PAGE_ID + "=? AND " + PAGE_LANGUAGE + "=?",
            new String[] { pageId, lang }, null, null, null);

    if ((c != null) && (c.getCount() > 0)) {
        itemExist = true;/* w w w. j a  v  a  2  s  .  co  m*/
    }
    c.close();
    return itemExist;
}

From source file:Main.java

public static String getPath(Context context, Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//  w w w .  j a  v a2  s.com
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}

From source file:Main.java

/**
 * get image path by uri/*from  w w  w . jav a 2 s  .com*/
 *
 * @param context context
 * @param uri     uri
 * @return image path
 */
public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null,
            null);
    cursor.moveToNext();
    String path = cursor.getString(cursor.getColumnIndex(ImageColumns.DATA));
    cursor.close();
    return path;
}

From source file:Main.java

public static int getSmsCount(Context context) {
    try {/*w  ww.  j av  a  2 s  .  c o m*/
        int result = 0;
        Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"),
                new String[] { "count(_id)", }, null, null, null);
        if (c.moveToFirst()) {
            result = c.getInt(0);
        }
        c.close();
        return result;
    } catch (Throwable t) {
        LOGE("getSmsCount: " + t.getMessage());
        t.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static String getImagePath(Context context, String id) {
    String path = null;/*from  w  w w  .ja  va 2 s  .  c om*/
    Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, null, Media._ID + "=?",
            new String[] { id }, null);
    while (cursor.moveToNext()) {
        path = cursor.getString(cursor.getColumnIndex(Media.DATA));
    }
    cursor.close();
    return path;
}

From source file:Main.java

public static int getMaxSize(Context context) {
    // Note that this URI is safe to call on the UI thread.
    Cursor c = context.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
            new String[] { DisplayPhoto.DISPLAY_MAX_DIM }, null, null, null);
    try {/*ww  w .ja  v a  2 s  .c  om*/
        c.moveToFirst();
        return c.getInt(0);
    } finally {
        c.close();
    }
}

From source file:Main.java

public static final String getTelefone(final Context contexto, final String idContato) {
    ContentResolver cr = contexto.getContentResolver();
    Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + idContato, null, null);
    String numero = "";
    while (phones.moveToNext()) {
        numero = phones.getString(phones.getColumnIndex(Phone.NUMBER));
        break;//  w  w w.j  a  va 2  s  . com
    }
    phones.close();
    return numero;
}