List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java
/** * Move a Cursor to a id/*from www . j a v a2 s . co 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:Main.java
public static Object cursorValue(String column, Cursor cr) { Object value = false;//from w w w .j ava 2 s . com int index = cr.getColumnIndex(column); switch (cr.getType(index)) { case Cursor.FIELD_TYPE_NULL: value = false; break; case Cursor.FIELD_TYPE_STRING: value = cr.getString(index); break; case Cursor.FIELD_TYPE_INTEGER: value = cr.getInt(index); break; case Cursor.FIELD_TYPE_FLOAT: value = cr.getFloat(index); break; case Cursor.FIELD_TYPE_BLOB: value = cr.getBlob(index); break; } return value; }
From source file:Main.java
/** * Returns the Id for an artist.//from w w w.j a v a 2 s .c o m * * @param context The {@link Context} to use. * @param name The name of the artist. * @return The ID for an artist. */ public static final long getIdForArtist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[] { name }, ArtistColumns.ARTIST); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
From source file:com.cyanogenmod.filemanager.util.MediaHelper.java
/** * Method that converts a file reference to a content uri reference * * @param cr A content resolver//from w w w . ja va2s. c o m * @param path The path to search * @param volume The volume * @return Uri The content uri or null if file not exists in the media database */ private static Uri fileToContentUri(ContentResolver cr, String path, String volume) { final String[] projection = { BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE }; final String where = MediaColumns.DATA + " = ?"; Uri baseUri = MediaStore.Files.getContentUri(volume); Cursor c = cr.query(baseUri, projection, where, new String[] { path }, null); try { if (c != null && c.moveToNext()) { int type = c.getInt(c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE)); if (type != 0) { // Do not force to use content uri for no media files long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID)); return Uri.withAppendedPath(baseUri, String.valueOf(id)); } } } finally { IOUtils.closeQuietly(c); } return null; }
From source file:Main.java
/** * Returns The ID for a playlist.//from w w w.j av a2 s . c o m * * @param context The {@link Context} to use. * @param name The name of the playlist. * @return The ID for a playlist. */ public static final long getIdForPlaylist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, PlaylistsColumns.NAME + "=?", new String[] { name }, PlaylistsColumns.NAME); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
From source file:Main.java
private static int getOrientation(Context context, Uri photoUri) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor.getCount() != 1) { return -1; }/*from w w w .ja v a 2s . co m*/ cursor.moveToFirst(); return cursor.getInt(0); }
From source file:Main.java
public static int getMessageTypeByThreadAndBody(Context context, long threadId, String body) { int type = 1; final String[] projection = new String[] { " sms.type " + " from sms " + " where sms.thread_id = " + threadId + " and sms.body = '" + body + "' --" }; // Create cursor /*/*from w ww .jav a 2s .c om*/ * Cursor cursor = context.getContentResolver().query( SMS_CONTENT_URI, * projection, null, null, null); */ Cursor cursor = context.getContentResolver().query(SMS_CONTENT_URI, new String[] { "type" }, "sms.thread_id = ? and sms.body = ?", new String[] { String.valueOf(threadId), body }, null); if (cursor != null) { try { if (cursor.getCount() > 0) { while (cursor.moveToNext()) { type = cursor.getInt(cursor.getColumnIndexOrThrow("type")); return type; } } } catch (Exception e) { e.printStackTrace(); } finally { cursor.close(); } } return type; }
From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java
private static ContentValues queryDrinkDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null); try {/*w w w .j av a 2s . c om*/ if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(SessionsQuery.UPDATED)); values.put(Drinks.DRINK_STARRED, cursor.getInt(SessionsQuery.STARRED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
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 v a 2 s .co 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 String checkNull(Context context, int lastImageId, File fileCapture) { final String[] imageColumns = { Images.Media._ID, Images.Media.DATA }; final String imageOrderBy = Images.Media._ID + " DESC"; final String imageWhere = Images.Media._ID + ">?"; final String[] imageArguments = { Integer.toString(lastImageId) }; ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere, imageArguments, imageOrderBy); if (cursor == null) return null; String newpath = null;// w w w. ja v a2 s. c om if (cursor.getCount() >= 2) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID)); String data = cursor.getString(cursor.getColumnIndex(Images.Media.DATA)); if (data.equals(fileCapture.getPath())) { int rows = contentResolver.delete(Images.Media.EXTERNAL_CONTENT_URI, Images.Media._ID + "=?", new String[] { Long.toString(id) }); boolean ok = fileCapture.delete(); } else { newpath = data; } } } else { newpath = fileCapture.getPath(); Log.e("MediaUtils", "Not found duplicate."); } cursor.close(); return newpath; }