List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:Main.java
private static long fileUriFileSize(Context context, String contentUri) { long result = 0; String[] p = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.SIZE }; Uri uri = Uri.parse(contentUri);/*from w w w . j a v a 2 s .co m*/ String path = uri.getPath(); String last = Uri.parse(path).getLastPathSegment(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, p, // which columns MediaStore.MediaColumns.DISPLAY_NAME + "='" + last + "'", // which rows null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int scol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE); if (cursor.moveToFirst()) { result = cursor.getLong(scol); } } return (result); }
From source file:de.escoand.readdaily.DownloadHandler.java
public static float downloadProgress(final Context context, final String name) { Cursor cursor = Database.getInstance(context).getDownloads(); long id = 0;//from w ww .j a v a 2s .c o m float progress; // get download id while (cursor.moveToNext()) if (cursor.getString(cursor.getColumnIndex(Database.COLUMN_SUBSCRIPTION)).equals(name)) { id = cursor.getLong(cursor.getColumnIndex(Database.COLUMN_ID)); break; } cursor.close(); if (id <= 0) return SUBSCRIPTION_DOWNLOAD_UNKNOWN; // get download cursor = ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)) .query(new DownloadManager.Query().setFilterById(id)); if (!cursor.moveToFirst()) { Database.getInstance(context).removeDownload(id); return DOWNLOAD_ID_UNKNOWN; } // get progress progress = cursor.getFloat(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) / cursor.getFloat(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); cursor.close(); return progress; }
From source file:com.feathercoin.wallet.feathercoin.ExchangeRatesProvider.java
public static ExchangeRate getExchangeRate(final Cursor cursor) { final String currencyCode = cursor .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_CURRENCY_CODE)); final BigInteger rate = BigInteger .valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); return new ExchangeRate(currencyCode, rate, source); }
From source file:Main.java
public static long[] getAllSongs(Context context) { Cursor c = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.IS_MUSIC + "=1", null, null); try {/*from w w w. j a v a2 s. c o m*/ if (c == null || c.getCount() == 0) { return null; } int len = c.getCount(); long[] list = new long[len]; for (int i = 0; i < len; i++) { c.moveToNext(); list[i] = c.getLong(0); } return list; } finally { if (c != null) { c.close(); } } }
From source file:com.cyanogenmod.filemanager.util.MediaHelper.java
/** * Method that returns an array with all the unique albums paths and ids. * * @param cr The ContentResolver//from w ww.ja va 2 s . c o m * @return The albums map */ public static Map<String, Long> getAllAlbums(ContentResolver cr) { final Map<String, Long> albums = new HashMap<>(); final String[] projection = { "distinct " + MediaStore.Audio.Media.ALBUM_ID, "substr(" + MediaStore.Audio.Media.DATA + ", 0, length(" + MediaStore.Audio.Media.DATA + ") - length(" + MediaStore.Audio.Media.DISPLAY_NAME + "))" }; final String where = MediaStore.Audio.Media.IS_MUSIC + " = ?"; Cursor c = cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, where, new String[] { "1" }, null); if (c != null) { try { for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { long albumId = c.getLong(0); String albumPath = c.getString(1); albums.put(albumPath, albumId); } } finally { IOUtils.closeQuietly(c); } } return albums; }
From source file:com.bushstar.htmlcoin_android_wallet.ExchangeRatesProvider.java
public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) { final String currencyCode = cursor .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_CURRENCY_CODE)); final BigInteger rate = BigInteger .valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); return new ExchangeRate(currencyCode, rate, source); }
From source file:com.android.emailcommon.utility.AttachmentUtilities.java
/** * In support of deleting a message, find all attachments and delete associated attachment * files./*from w ww .j a v a2 s. com*/ * @param context * @param accountId the account for the message * @param messageId the message */ public static void deleteAllAttachmentFiles(Context context, long accountId, long messageId) { Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); Cursor c = context.getContentResolver().query(uri, Attachment.ID_PROJECTION, null, null, null); try { while (c.moveToNext()) { long attachmentId = c.getLong(Attachment.ID_PROJECTION_COLUMN); File attachmentFile = getAttachmentFilename(context, accountId, attachmentId); // Note, delete() throws no exceptions for basic FS errors (e.g. file not found) // it just returns false, which we ignore, and proceed to the next file. // This entire loop is best-effort only. attachmentFile.delete(); } } finally { c.close(); } }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Returns the RawContact id for a sample SyncAdapter contact, or 0 if the * sample SyncAdapter user isn't found.//from w ww . j a v a 2 s .co m * * @param context the Authenticator Activity context * @param userId the sample SyncAdapter user ID to lookup * @return the RawContact id, or 0 if not found */ private static List<Long> lookupAllContacts(ContentResolver resolver) { List<Long> result = new ArrayList<Long>(); final Cursor c = resolver.query(RawContacts.CONTENT_URI, AllUsersQuery.PROJECTION, AllUsersQuery.SELECTION, null, null); try { while (c.moveToNext()) { result.add(c.getLong(AllUsersQuery.COLUMN_ID)); } } finally { if (c != null) { c.close(); } } return result; }
From source file:Main.java
public static long[] getSongListForCursor(Cursor cursor) { if (cursor == null) { return sEmptyList; }/* ww w .j ava 2 s . com*/ int len = cursor.getCount(); long[] list = new long[len]; cursor.moveToFirst(); int colidx = -1; try { colidx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID); } catch (IllegalArgumentException ex) { colidx = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID); } for (int i = 0; i < len; i++) { list[i] = cursor.getLong(colidx); cursor.moveToNext(); } return list; }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Returns the RawContact id for a sample SyncAdapter contact, or 0 if the * sample SyncAdapter user isn't found.//from w ww .ja v a 2 s . c o m * * @param context the Authenticator Activity context * @param userId the sample SyncAdapter user ID to lookup * @return the RawContact id, or 0 if not found */ private static long lookupRawContact(ContentResolver resolver, String userName) { long authorId = 0; final Cursor c = resolver.query(RawContacts.CONTENT_URI, UserIdQuery.PROJECTION, UserIdQuery.SELECTION, new String[] { userName }, null); try { if (c.moveToFirst()) { authorId = c.getLong(UserIdQuery.COLUMN_ID); } } finally { if (c != null) { c.close(); } } return authorId; }