List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static String getPath(Context context, Uri contentUri) { Cursor cursor = null; try {/*from w w w . j av a2 s.co 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
/** * Find a download with the specified name. Returns -1 if none was * found.//from w ww . ja va 2 s . co m */ static long findPath(DownloadManager dm, String path) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); Cursor c = dm.query(query); if (!c.moveToFirst()) return -1; final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID); final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI); do { final String uri = c.getString(columnLocalURI); if (uri != null && uri.endsWith(path)) return c.getLong(columnID); } while (c.moveToNext()); return -1; }
From source file:Main.java
public static String getRealPathFromURI(Uri contentUri, Context ctx) { Log.d("thong", "Uri: " + contentUri.toString()); try {//from w w w . j a va 2 s. co m String realpath = ""; String[] proj = { MediaStore.Images.Media.DATA }; //Cursor cursor = ((Activity) ctx).managedQuery(contentUri, proj, null, null, null); Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); Log.d("thong", "Column count: " + cursor.getColumnCount()); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); realpath = cursor.getString(column_index); cursor.close(); return realpath; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:de.escoand.readdaily.DownloadHandler.java
public static void stopDownload(final Context context, final String name) { Database db = Database.getInstance(context); Cursor c = db.getDownloads(); long id = 0;//from w w w . j av a 2 s. c o m // get download id while (c.moveToNext()) if (c.getString(c.getColumnIndex(Database.COLUMN_SUBSCRIPTION)).equals(name)) { id = c.getLong(c.getColumnIndex(Database.COLUMN_ID)); break; } c.close(); if (id <= 0) return; // stop download ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).remove(id); db.removeDownload(id); }
From source file:Main.java
public static boolean isMediaScannerScanning(Context context) { boolean result = false; Cursor cursor = query(context, MediaStore.getMediaScannerUri(), new String[] { MediaStore.MEDIA_SCANNER_VOLUME }, null, null, null); if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst();/*from ww w . j ava 2s. co m*/ result = "external".equals(cursor.getString(0)); } cursor.close(); } return result; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSpeakersHandler.java
private static boolean isSpeakerUpdated(Uri uri, JSONObject speaker, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null); try {/*from www . j a v a 2s .co m*/ if (!cursor.moveToFirst()) return false; final String curFirstName = cursor.getString(SpeakersQuery.FIRST_NAME).toLowerCase().trim(); final String curLastName = cursor.getString(SpeakersQuery.LAST_NAME).toLowerCase().trim(); final String curBio = cursor.getString(SpeakersQuery.BIO).toLowerCase().trim(); final String curCompany = cursor.getString(SpeakersQuery.COMPANY).toLowerCase().trim(); final String newFirstName = speaker.has("firstName") ? speaker.getString("firstName").toLowerCase().trim() : curFirstName; final String newLastName = speaker.has("lastName") ? speaker.getString("lastName").toLowerCase().trim() : curLastName; final String newBio = speaker.has("bio") ? speaker.getString("bio").toLowerCase().trim() : curBio; final String newCompany = speaker.has("company") ? speaker.getString("company").toLowerCase().trim() : curCompany; return (!curFirstName.equals(newFirstName) || !curLastName.equals(newLastName) || !curBio.equals(newBio) || !curCompany.equals(newCompany)); } finally { cursor.close(); } }
From source file:Main.java
/** * Get a file path from a Uri.// w w w . j ava 2s . c om * * @param context * @param uri * @return * @throws URISyntaxException * * @author paulburke */ public static String getPath(Context context, Uri uri) throws URISyntaxException { if (DEBUG) Log.d(TAG + " File -", "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString()); if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:co.rewen.statex.AsyncLocalStorageUtil.java
/** * Returns the value of the given key, or null if not found. *///from ww w . j av a2 s.c o m /* package */ static @Nullable String getItemImpl(SQLiteDatabase db, String key) { String[] columns = { VALUE_COLUMN }; String[] selectionArgs = { key }; Cursor cursor = db.query(TABLE_STATE, columns, KEY_COLUMN + "=?", selectionArgs, null, null, null); try { if (!cursor.moveToFirst()) { return null; } else { return cursor.getString(0); } } finally { cursor.close(); } }
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
/** * Get the value of the data column for this Uri. This is useful for * MediaStore Uris, and other file-based ContentProviders. * * @param context The context./*from w ww . j a va 2 s . com*/ * @param uri The Uri to query. * @param selection (Optional) Filter used in the query. * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { final String[] projection = { MediaStore.MediaColumns.DATA }; final Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null) { try { if (cursor.moveToFirst()) { return cursor.getString(0); } } finally { cursor.close(); } } return null; }