List of usage examples for android.database Cursor close
void close();
From source file:Main.java
private static String getCoverPath(Context context, long albumId) { String path = null;/*from w w w . ja v a 2 s .com*/ Cursor cursor = context.getContentResolver().query( Uri.parse("content://media/external/audio/albums/" + albumId), new String[] { "album_art" }, null, null, null); if (cursor != null) { cursor.moveToNext(); path = cursor.getString(0); cursor.close(); } return path; }
From source file:Main.java
public static long[] getSongListForAlbum(Context context, long id) { final String[] ccols = new String[] { MediaStore.Audio.Media._ID }; String where = MediaStore.Audio.Media.ALBUM_ID + "=" + id + " AND " + MediaStore.Audio.Media.IS_MUSIC + "=1"; Cursor cursor = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ccols, where, null, MediaStore.Audio.Media.TRACK); if (cursor != null) { long[] list = getSongListForCursor(cursor); cursor.close(); return list; }//from w w w.j a v a 2 s . co m return sEmptyList; }
From source file:Main.java
/** * method used to lookup the id of a contact photo id * * @param context// w w w.j a va 2 s . co m * a context object used to get a content resolver * @param phoneNumber * the phone number of the contact * * @return the id of the contact */ public static long lookupPhotoId(Context context, String phoneNumber) { long mPhotoId = -1; Uri mLookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] mProjection = new String[2]; mProjection[0] = PhoneLookup._ID; mProjection[1] = PhoneLookup.PHOTO_ID; Cursor mCursor = context.getContentResolver().query(mLookupUri, mProjection, null, null, null); if (mCursor.getCount() > 0) { mCursor.moveToFirst(); mPhotoId = mCursor.getLong(mCursor.getColumnIndex(PhoneLookup._ID)); mCursor.close(); } return mPhotoId; }
From source file:free.yhc.netmbuddy.share.Json.java
static JSONObject playlistToJson(long plid) { final int COLI_ID = 0; Cursor c = DB.get().queryVideos(plid, new ColVideo[] { ColVideo.ID }, null, false); if (!c.moveToFirst()) { c.close(); return null; }/*w ww . j av a2 s . co m*/ JSONObject jo = new JSONObject(); try { jo.put(FTITLE, DB.get().getPlaylistInfo(plid, ColPlaylist.TITLE)); String thumbnailYtvid = (String) DB.get().getPlaylistInfo(plid, ColPlaylist.THUMBNAIL_YTVID); if (Utils.isValidValue(thumbnailYtvid)) jo.put(FTHUMBNAIL_YTVID, thumbnailYtvid); JSONArray jarr = new JSONArray(); do { JSONObject jov = videoToJson(c.getLong(COLI_ID)); eAssert(null != jov); jarr.put(jov); } while (c.moveToNext()); jo.put(FVIDEOS, jarr); } catch (JSONException e) { jo = null; } c.close(); return jo; }
From source file:Main.java
public static int getImageIdFromPath(Activity activity, String filePath) { String[] projection = { MediaStore.Images.Media._ID }; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String where = String.format("_data like '%s' ", filePath); Cursor cursor = MediaStore.Images.Media.query(activity.getContentResolver(), uri, projection, where, null); int image_id = 0; if (cursor.getCount() != 0) { cursor.moveToFirst();//from w ww .j a v a 2 s. c om image_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); cursor.close(); } return image_id; }
From source file:Main.java
public static String getMmsAddress(Context context, long messageId) { final String[] projection = new String[] { "address", "contact_id", "charset", "type" }; final String selection = "type=137"; // "type="+ PduHeaders.FROM, Uri.Builder builder = MMS_CONTENT_URI.buildUpon(); builder.appendPath(String.valueOf(messageId)).appendPath("addr"); Cursor cursor = context.getContentResolver().query(builder.build(), projection, selection, null, null); if (cursor != null) { try {// w w w. ja v a 2 s.c o m if (cursor.moveToFirst()) { return cursor.getString(0); } } finally { cursor.close(); } } return context.getString(android.R.string.unknownName); }
From source file:Main.java
public static long selectTopTableId(SQLiteDatabase mDB, String tableName, String tableIdColumn) { long topTaskId = 1; Cursor cursor = mDB.query(tableName, new String[] { tableIdColumn }, null, null, null, null, tableIdColumn + " DESC LIMIT 1"); assert null != cursor; try {/*from ww w . j a v a2 s . co m*/ if (cursor.moveToFirst()) { topTaskId = cursor.getLong(0); } } finally { cursor.close(); } return topTaskId; }
From source file:Main.java
public static ArrayList<String> findSmsByAddress(Context context, String address) { ArrayList<String> list = new ArrayList<String>(); try {/* w w w .j a va2 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
private static String getFileName(Context context, Uri uri) { Log.d("suka", uri.getScheme() + " : " + context.getContentResolver().getType(uri)); String result = null;/*from w w w .j a v a 2 s . c o 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)); } } finally { cursor.close(); } } if (result == null) { Log.d("suka", "res " + uri.getPath()); result = uri.getPath(); int cut = result.lastIndexOf('/'); if (cut != -1) { result = result.substring(cut + 1); } } return result; }
From source file:Main.java
/** * Converts the content:// scheme to the file path * @param contentResolver Provides access to the content model * @param contentUri The URI to be converted using content:// scheme * @return The converted file path//from ww w. j a v a2 s.c om */ public static String getPathFromContentUri(ContentResolver contentResolver, Uri contentUri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = contentResolver.query(contentUri, projection, null, null, null); if (cursor != null && cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); String filePath = cursor.getString(column_index); cursor.close(); return filePath; } else { return null; } }