List of usage examples for android.database Cursor close
void close();
From source file:Main.java
private static Set<Integer> getAllAvailableProtocolVersions(Context context) { ContentResolver contentResolver = context.getContentResolver(); Set<Integer> allAvailableVersions = new HashSet<Integer>(); Uri uri = Uri.parse("content://com.facebook.orca.provider.MessengerPlatformProvider/versions"); String[] projection = new String[] { "version" }; Cursor c = contentResolver.query(uri, projection, null, null, null); if (c != null) { try {/*w w w . j a v a2s. c om*/ int versionColumnIndex = c.getColumnIndex("version"); while (c.moveToNext()) { int version = c.getInt(versionColumnIndex); allAvailableVersions.add(version); } } finally { c.close(); } } return allAvailableVersions; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try {/*from w ww.ja v a 2 s .c om*/ String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public final static String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try {//ww w . ja v a2s .c o m String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public static String getPath(Context context, Uri contentUri) { Cursor cursor = null; try {/* ww w . j a v a 2 s. c o m*/ String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
private static List<String> getColumns(SQLiteDatabase db, String tableName) { List<String> columns = new ArrayList<>(); Cursor cursor = null; try {//ww w. ja va 2s . co m cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null); if (cursor != null) { columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames())); } } catch (Exception e) { Log.v(tableName, e.getMessage(), e); e.printStackTrace(); } finally { if (cursor != null) cursor.close(); } return columns; }
From source file:net.peterkuterna.android.apps.devoxxsched.util.SyncUtils.java
public static String getLocalMd5(ContentResolver resolver, String url) { final String syncId = Sync.generateSyncId(url); final Uri uri = Sync.buildSyncUri(syncId); Cursor cursor = resolver.query(uri, SyncQuery.PROJECTION, null, null, null); try {// w w w .ja va 2s. c om if (!cursor.moveToFirst()) return ""; return cursor.getString(SyncQuery.MD5); } finally { cursor.close(); } }
From source file:Main.java
/** * Returns the Id for an artist.// w w w . j av 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:Main.java
/** * Returns The ID for a playlist.//from w w w .j a v a 2s. c om * * @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
static String getFileName(Context context, Uri uri) { String result = null;//from w ww . j a v a2 s. co m if (uri.getScheme().equals("content")) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } } if (result == null) { result = uri.getPath(); int cut = result.lastIndexOf(File.separator); if (cut != -1) { result = result.substring(cut + 1); } } return result; }
From source file:Main.java
public static String getRealFilePath(Context context, Uri uri) { if (null == uri) return null; String scheme = uri.getScheme(); String data = null;//from w ww .j a va 2 s . c o m if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }