Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail( getContentResolver(), selectedImageUri, MediaStore.Images.Thumbnails.MINI_KIND, null ); if( cursor != null && cursor.getCount() > 0 ) { cursor.moveToFirst();//**EDIT** String uri = cursor.getString( cursor.getColumnIndex( MediaStore.Images.Thumbnails.DATA ) ); }
public 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; } cursor.moveToFirst(); return cursor.getInt(0); }
@Override protected int getImageOrientation() throws IOException { Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null); if (cursor == null || cursor.getCount() != 1) { return 0; } cursor.moveToFirst(); int orientation = cursor.getInt(0); cursor.close(); return orientation; } }
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */ public List<RelationSource2> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<RelationSource2> list = new ArrayList<RelationSource2>(count); if (cursor.moveToFirst()) { if (identityScope != null) { identityScope.lock(); identityScope.reserveRoom(count); } try { do { list.add(loadCurrentDeep(cursor, false)); } while (cursor.moveToNext()); } finally { if (identityScope != null) { identityScope.unlock(); } } } return list; }
@NonNull @Override public Result<List<T>> merge(@NonNull final SQLiteDatabase database, @NonNull final SqlRequest input) { try { final Cursor cursor = database.rawQuery(input.sql, input.arguments); try { final int count = cursor.getCount(); if (count == 0) { return success(Collections.<T>emptyList()); } final List<T> items = new ArrayList<>(count); while (cursor.moveToNext()) { items.add(cursorToItem.apply(cursor)); } return success(items); } finally { cursor.close(); } } catch (final SQLException e) { return failure(e); } } }
MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount()); while (source.moveToNext()) { MatrixCursor.RowBuilder row = cursor.newRow(); for (int i = 0; i < columnNames.length; i++) { row.add(source.getString(i));
private long getAffectedRowCount() { synchronized (database) { Cursor cursor = null; try { cursor = database.rawQuery(GET_CHANGES_QUERY, null); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { return cursor.getLong(cursor.getColumnIndex(CHANGES_QUERY_RESULT)); } else { return 0; } } finally { tryCloseCursor(cursor); } } }
int rotation =-1; long fileSize = new File(filePath).length(); Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(captureTime/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc"); if (mediaCursor != null && captureTime != 0 && mediaCursor.getCount() !=0 ) { while(mediaCursor.moveToNext()){ long size = mediaCursor.getLong(1); //Extra check to make sure that we are getting the orientation from the proper file if(size == fileSize){ rotation = mediaCursor.getInt(0); break; } } }
public String getContactDisplayNameByNumber(String number) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); String name = "?"; ContentResolver contentResolver = getContentResolver(); Cursor contactLookup = contentResolver.query(uri, new String[] {BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); try { if (contactLookup != null && contactLookup.getCount() > 0) { contactLookup.moveToNext(); name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); //String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID)); } } finally { if (contactLookup != null) { contactLookup.close(); } } return name; }
public static final int getSongCountForPlaylist(final Context context, final long playlistId) { Cursor c = context.getContentResolver().query( MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId), new String[]{BaseColumns._ID}, MUSIC_ONLY_SELECTION, null, null); if (c != null) { int count = 0; if (c.moveToFirst()) { count = c.getCount(); } c.close(); c = null; return count; } return 0; }
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */ public List<RelationEntity> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<RelationEntity> list = new ArrayList<RelationEntity>(count); if (cursor.moveToFirst()) { if (identityScope != null) { identityScope.lock(); identityScope.reserveRoom(count); } try { do { list.add(loadCurrentDeep(cursor, false)); } while (cursor.moveToNext()); } finally { if (identityScope != null) { identityScope.unlock(); } } } return list; }
public int count() { SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("select * from cars", null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getInt(0); } else { return 0; } } }
/** Returns the count (number of results matching the query). Uses SELECT COUNT (*) sematics. */ public long count() { checkThread(); Cursor cursor = dao.getDatabase().rawQuery(sql, parameters); try { if (!cursor.moveToNext()) { throw new DaoException("No result for count"); } else if (!cursor.isLast()) { throw new DaoException("Unexpected row count: " + cursor.getCount()); } else if (cursor.getColumnCount() != 1) { throw new DaoException("Unexpected column count: " + cursor.getColumnCount()); } return cursor.getLong(0); } finally { cursor.close(); } }
public ArrayList<FinishedMission> loadFinishedMissions() { SQLiteDatabase database = downloadMissionHelper.getReadableDatabase(); Cursor cursor = database.query(MISSIONS_TABLE_NAME, null, null, null, null, null, DownloadMissionHelper.KEY_TIMESTAMP); int count = cursor.getCount(); if (count == 0) return new ArrayList<>(1); ArrayList<FinishedMission> result = new ArrayList<>(count); while (cursor.moveToNext()) { result.add(DownloadMissionHelper.getMissionFromCursor(cursor)); } return result; }
ContentResolver cr = getContentResolver(); Cursor cur = cr.query(Contacts.CONTENT_URI, null, null, null, null); if(cur != null && cur.moveToFirst()) { String id = cur.getString(cur.getColumnIndex(Contacts._ID)); if (cur.getCount() > 0) { ...
public TreeEntity loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */ public List<TreeEntity> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<TreeEntity> list = new ArrayList<TreeEntity>(count); if (cursor.moveToFirst()) { if (identityScope != null) { identityScope.lock(); identityScope.reserveRoom(count); } try { do { list.add(loadCurrentDeep(cursor, false)); } while (cursor.moveToNext()); } finally { if (identityScope != null) { identityScope.unlock(); } } } return list; }
LazyList(InternalQueryDaoAccess<E> daoAccess, Cursor cursor, boolean cacheEntities) { this.cursor = cursor; this.daoAccess = daoAccess; size = cursor.getCount(); if (cacheEntities) { entities = new ArrayList<E>(size); for (int i = 0; i < size; i++) { entities.add(null); } } else { entities = null; } if (size == 0) { cursor.close(); } lock = new ReentrantLock(); }