List of usage examples for android.database Cursor close
void close();
From source file:Main.java
public static boolean is_any_info_available(SQLiteDatabase db) { boolean result = false; Cursor cInfo = db.rawQuery("select INFO_ID from TESTING", null); if (cInfo != null) { if (cInfo.moveToFirst()) { result = true;// www.jav a 2 s .com } } if (cInfo != null) cInfo.close(); return result; }
From source file:Main.java
public static boolean isShortCutExist(Context context) { boolean isExist = false; int version = android.os.Build.VERSION.SDK_INT; Uri uri = null;/*from ww w . ja v a2s. co m*/ if (version < 2.0) { uri = Uri.parse("content://com.android.launcher.settings/favorites"); } else { uri = Uri.parse("content://com.android.launcher2.settings/favorites"); } String selection = " title = ?"; String[] selectionArgs = new String[] { "YouTube" }; Cursor c = context.getContentResolver().query(uri, null, selection, selectionArgs, null); if (c != null && c.getCount() > 0) { isExist = true; } if (c != null) { c.close(); } return isExist; }
From source file:Main.java
public static String getAbsoluteImagePath(Context context, Uri uri) { // can post image String[] proj = { Media.DATA }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(Media.DATA); cursor.moveToFirst();/* w ww . j a v a2s. c o m*/ String path = cursor.getString(column_index); cursor.close(); return path; }
From source file:Main.java
static ImmutableSet<String> getColumns(SQLiteDatabase db, String table) { Cursor cursor = db.query(table, null, null, null, null, null, null, "0"); if (cursor != null) { try {/*from www. j a v a 2 s .c o m*/ return ImmutableSet.copyOf(cursor.getColumnNames()); } finally { cursor.close(); } } return ImmutableSet.of(); }
From source file:net.niyonkuru.koodroid.html.SubscribersHandler.java
private static boolean subscriberExists(Uri uri, ContentResolver resolver) { Cursor cursor = resolver.query(uri, null, null, null, null); try {//w w w .j a v a2 s .c o m return cursor.moveToFirst(); } finally { cursor.close(); } }
From source file:Main.java
public static String getFileFromStorage(Context context, Intent data) { Uri pickedImage = data.getData();//from w ww. j a v a2 s . com String[] filePath = { MediaStore.Images.Media.DATA }; String path = ""; Cursor cursor = context.getContentResolver().query(pickedImage, filePath, null, null, null); if (cursor != null) { cursor.moveToFirst(); path = cursor.getString(cursor.getColumnIndex(filePath[0])); cursor.close(); } return path; }
From source file:net.sf.sprockets.database.Cursors.java
/** * Close the cursor if requested./*w ww.j a v a 2 s .c om*/ */ private static void close(Cursor cursor, boolean close) { if (close) { cursor.close(); } }
From source file:Main.java
static int getCardId(Context context) { ContentResolver res = context.getContentResolver(); Cursor c = res.query(Uri.parse("content://media/external/fs_id"), null, null, null, null); int id = -1;//from ww w. j a v a2 s.com if (c != null) { c.moveToFirst(); id = c.getInt(0); c.close(); } return id; }
From source file:Main.java
/** * Helper method to reslove a uri into a path. * // ww w.j av a 2s .c o m * @param contentURI * a uri path * @return the path as a string */ public static String getRealPathFromURI(Uri contentURI, Context context) { Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); String path = cursor.getString(idx); cursor.close(); return path; }
From source file:Main.java
public static long[] readIds(Cursor cursor) { long[] arr = new long[cursor.getCount()]; int count = 0; try {/*from w ww . ja v a 2 s . com*/ while (cursor.moveToNext()) { arr[count++] = cursor.getLong(0); } } finally { cursor.close(); } return arr; }