List of usage examples for android.database Cursor close
void close();
From source file:fr.mixit.android.io.RemoteSessionsHandler.java
private static boolean isSessionTagsUpdated(Uri uri, JSONArray tags, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, TagsQuery.PROJECTION, null, null, null); try {// w w w . ja v a 2 s.c o m if (!cursor.moveToFirst()) return false; return cursor.getCount() != tags.length(); } finally { cursor.close(); } }
From source file:Main.java
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; String column = MediaStore.Images.Media.DATA; String[] projection = { column }; try {/*from w ww .j a v a 2 s .c o m*/ cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
/** * Returns the ID for an album./*from w ww .ja v a 2s . c o m*/ * * @param context The {@link Context} to use. * @param albumName The name of the album. * @param artistName The name of the artist * @return The ID for an album. */ public static final long getIdForAlbum(final Context context, final String albumName, final String artistName) { Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, AlbumColumns.ALBUM + "=? AND " + AlbumColumns.ARTIST + "=?", new String[] { albumName, artistName }, AlbumColumns.ALBUM); 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.docd.purefm.test.MediaStoreUtilsTest.java
private static boolean isFileInMediaStore(final ContentResolver resolver, final GenericFile file) { final Uri uri = MediaStoreUtils.getContentUri(file); final Pair<String, String[]> selection = MediaStoreUtils.dataSelection(file.toFile()); final Cursor c = resolver.query(uri, new String[] { MediaStore.Files.FileColumns._ID }, selection.first, selection.second, null);//from ww w. j a v a2s . co m if (c != null) { try { if (c.moveToFirst()) { return c.getLong(0) != 0; } } finally { c.close(); } } return false; }
From source file:com.goliathonline.android.kegbot.io.RemoteTapHandler.java
private static ContentValues queryTapDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, TapsQuery.PROJECTION, null, null, null); try {/* w w w . j a v a 2 s . co m*/ if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(TapsQuery.UPDATED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:Main.java
/** * Return file size from Uri//from w ww. j a va2 s. com * * @param uri file URI * @return return file size */ public static long getFileSizeFromUri(Context context, Uri uri) { long size = 0; if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = null; try { cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE); size = cursor.getInt(column_index); } } finally { if (cursor != null) { cursor.close(); } } } else if (uri.getScheme().toString().compareTo("file") == 0) { final File file = new File(uri.getPath()); size = file.length(); } return size; }
From source file:Main.java
/** * Looks up a contacts display name by contact id - if not found, the * address (phone number) will be formatted and returned instead. *///from w w w . ja v a 2 s . co m public static String getPersonName(Context context, String id, String address) { // Check for id, if null return the formatting phone number as the name if (id == null || "".equals(id.trim())) { if (address != null && !"".equals(address.trim())) { return PhoneNumberUtils.formatNumber(address); } else { return null; } } Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.CONTENT_URI, id), new String[] { Contacts.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); return name; } } finally { cursor.close(); } } if (address != null) { return PhoneNumberUtils.formatNumber(address); } return null; }
From source file:fr.mixit.android.io.RemoteSessionsHandler.java
private static boolean isSessionSpeakersUpdated(Uri uri, JSONArray speakers, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null); try {//from w w w. j a v a 2s. co m if (!cursor.moveToFirst()) return false; return cursor.getCount() != speakers.length(); } finally { cursor.close(); } }
From source file:Main.java
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {//from www. j ava 2 s . com cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
public static boolean doesAvatarHashExist(ContentResolver resolver, Uri queryUri, String jid, String hash) { StringBuilder buf = new StringBuilder(Imps.Avatars.CONTACT); buf.append("=?"); buf.append(" AND "); buf.append(Imps.Avatars.HASH);// w w w .j av a 2 s .c om buf.append("=?"); String[] selectionArgs = new String[] { jid, hash }; Cursor cursor = resolver.query(queryUri, null, buf.toString(), selectionArgs, null); if (cursor == null) return false; try { return cursor.getCount() > 0; } finally { cursor.close(); } }