List of usage examples for android.database Cursor getCount
int getCount();
From source file:Main.java
public static String getThumbnailPathFromURI(Uri contentUri, ContentResolver content_resolver) { String uri = ""; Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(content_resolver, ContentUris.parseId(contentUri), MediaStore.Images.Thumbnails.MINI_KIND, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst();//**EDIT** uri = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA)); }/*from w ww . j a v a 2 s. c o m*/ return uri; }
From source file:Main.java
public static String getAbsoluteImagePath(Context context, Uri uri) { String imagePath = ""; Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { imagePath = cursor.getString(column_index); }//from w w w .j a v a 2s. c o m } return imagePath; }
From source file:Main.java
public static LinkedList<Pair<Integer, String>> retrieveIntegerStringPairFromCursor(Cursor cursor, String integerColumnName, String stringColumnName) { LinkedList<Pair<Integer, String>> result = new LinkedList<Pair<Integer, String>>(); if (null == cursor || 0 == cursor.getCount()) { return result; }/*from w w w . j a va 2s . c o m*/ try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { Integer integerVal = cursor.getInt(cursor.getColumnIndex(integerColumnName)); String stringVal = cursor.getString(cursor.getColumnIndexOrThrow(stringColumnName)); result.add(new Pair(integerVal, stringVal)); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return result; }
From source file:Main.java
public static int getOrientation(Context context, Uri bitmapUri) { Cursor cursor = context.getContentResolver().query(bitmapUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor == null || cursor.getCount() != 1) { return -1; }/* w ww. j a v a 2s .c o m*/ cursor.moveToFirst(); return cursor.getInt(0); }
From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java
/** * Move a Cursor to a id/*from ww w .j a v a2s . c o m*/ * This assumes that the cursor is sorted by id * @return true if the element could be found. */ public static boolean moveCursorToId(Cursor cursor, int column, int id) { int left = 0; int right = cursor.getCount() - 1; while (left <= right) { int middle = (left + right) / 2; cursor.moveToPosition(middle); int val = cursor.getInt(column); if (val == id) return true; if (val > id) right = middle - 1; else left = middle + 1; } return false; }
From source file:net.sf.sprockets.database.Cursors.java
/** * Get the number of rows in the cursor. * * @param close true to close the cursor or false to leave it open *//*from www.ja va 2 s.co m*/ public static int count(Cursor cursor, boolean close) { int count = cursor.getCount(); close(cursor, close); return count; }
From source file:Main.java
public static boolean isMediaScannerScanning(Context context) { boolean result = false; Cursor cursor = query(context, MediaStore.getMediaScannerUri(), new String[] { MediaStore.MEDIA_SCANNER_VOLUME }, null, null, null); if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst();/* ww w .j a va2s .co m*/ result = "external".equals(cursor.getString(0)); } cursor.close(); } return result; }
From source file:Main.java
public static boolean isMediaScannerScanning(Context context) { boolean result = false; Cursor cursor = query(context, MediaStore.getMediaScannerUri(), new String[] { MediaStore.MEDIA_SCANNER_VOLUME }, null, null, null); if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst();//from w ww .ja v a 2 s . co m result = "external".equals(cursor.getString(0)); } cursor.close(); } return result; }
From source file:Main.java
public static ArrayList<String> findSmsByAddress(Context context, String address) { ArrayList<String> list = new ArrayList<String>(); try {//from w ww . j a v a2 s . c om Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"), new String[] { "_id", "address" }, "address = ?", new String[] { address }, null); if (!c.moveToFirst() || c.getCount() == 0) { LOGI("there are no more messages"); c.close(); return list; } do { list.add(c.getString(0)); } while (c.moveToNext()); c.close(); } catch (Exception e) { LOGE("findSmsByAddress: " + e.getMessage()); } return list; }
From source file:Main.java
public static int getOrientation(Context context, Uri photoUri, File file) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor != null && cursor.getCount() != 1) { cursor.moveToFirst();//from ww w .j ava 2s . co m return cursor.getInt(0); } int rotate = 0; ExifInterface exif = null; try { exif = new ExifInterface(file == null ? getPath(context, photoUri) : file.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_NORMAL: rotate = 0; break; } return rotate; }