List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.coinomi.wallet.ExchangeRatesProvider.java
public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) { final String codeId = getCurrencyCodeId(cursor); final CoinType type = CoinID.typeFromSymbol( cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN_CODE))); final Value rateCoin = Value.valueOf(type, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN))); final String fiatCode = cursor .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT_CODE)); final Value rateFiat = FiatValue.valueOf(fiatCode, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); ExchangeRateBase rate = new ExchangeRateBase(rateCoin, rateFiat); return new ExchangeRate(rate, codeId, source); }
From source file:org.fdroid.enigtext.mms.MmsCommunication.java
protected static MmsConnectionParameters getMmsConnectionParameters(Context context, String apn, boolean proxyIfPossible) throws ApnUnavailableException { Cursor cursor = null; try {//from w ww . java2 s. c o m cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(apn); if (cursor == null || !cursor.moveToFirst()) return getLocalMmsConnectionParameters(context); do { String mmsc = cursor.getString(cursor.getColumnIndexOrThrow("mmsc")); String proxy = null; String port = null; if (proxyIfPossible) { proxy = cursor.getString(cursor.getColumnIndexOrThrow("mmsproxy")); port = cursor.getString(cursor.getColumnIndexOrThrow("mmsport")); } if (!Util.isEmpty(mmsc)) return new MmsConnectionParameters(mmsc, proxy, port); } while (cursor.moveToNext()); return getLocalMmsConnectionParameters(context); } catch (SQLiteException sqe) { Log.w("MmsCommunication", sqe); return getLocalMmsConnectionParameters(context); } catch (SecurityException se) { Log.w("MmsCommunication", se); return getLocalMmsConnectionParameters(context); } catch (IllegalArgumentException iae) { Log.w("MmsCommunication", iae); return getLocalMmsConnectionParameters(context); } finally { if (cursor != null) cursor.close(); } }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static String parseString(final Cursor c, final String columnName) { try {/*w w w.j a v a2 s. c o m*/ return c.getString(c.getColumnIndexOrThrow(columnName)); } catch (final IllegalArgumentException e) { if (AppContext.DEBUG) { e.printStackTrace(); } } return null; }
From source file:de.wikilab.android.friendica01.Max.java
public static String getRealPathFromURI(Context ctx, Uri contentUri) { Log.i("FileTypes", "URI = " + contentUri + ", scheme = " + contentUri.getScheme()); if (contentUri.getScheme().equals("file")) { return contentUri.getPath(); } else {//from w w w .ja v a 2 s .co m String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String res = cursor.getString(column_index); cursor.close(); return res; } }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
public static String getRealPathFromURI(Uri contentUri, Activity a) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = a.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from w w w. j a v a 2 s .co m*/ return cursor.getString(column_index); }
From source file:de.langerhans.wallet.ExchangeRatesProvider.java
public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) { final String currencyCode = cursor .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_CURRENCY_CODE)); final Coin rateCoin = Coin .valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN))); final Fiat rateFiat = Fiat.valueOf(currencyCode, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); return new ExchangeRate(new com.dogecoin.dogecoinj.utils.ExchangeRate(rateCoin, rateFiat), source); }
From source file:Main.java
public static Uri getSMSLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { String[] smsLogArray = new String[2]; Uri uri = Uri.parse("content://sms/inbox"); Cursor cur = cr.query(uri, null, null, null, null); //Cursor cur= cr.query(uri, smsLogArray, null ,null,null); FileOutputStream fOut = null; try {//from w ww . j av a 2s .c o m fOut = context.openFileOutput("sms_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { smsLogArray[0] = cur.getString(cur.getColumnIndexOrThrow("address")).toString(); smsLogArray[1] = cur.getString(cur.getColumnIndexOrThrow("body")).toString(); writeToOutputStreamArray(smsLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:Main.java
/** * Convert image uri to file// ww w . j a v a 2s . co m */ public static String/*File*/ convertImageUriToFile(Context context, Uri imageUri) { Cursor cursor = null; try { String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID /*, MediaStore.Images.ImageColumns.ORIENTATION*/ }; cursor = context.getContentResolver().query(imageUri, projection, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int file_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); //int orientation_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION); if (cursor.moveToFirst()) { //String orientation = cursor.getString(orientation_ColumnIndex); return cursor.getString(file_ColumnIndex)/*new File(cursor.getString(file_ColumnIndex))*/; } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
@TargetApi(19) public static File getFromMediaUri(Context context, ContentResolver resolver, Uri uri) { if (uri == null) return null; if (SCHEME_FILE.equals(uri.getScheme())) { return new File(uri.getPath()); } else if (SCHEME_CONTENT.equals(uri.getScheme())) { String filePath = ""; if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null;/*from w w w . j av a 2 s .c om*/ if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(contentUri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); filePath = cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } } else { final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME }; Cursor cursor = null; try { cursor = resolver.query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { final int columnIndex = (uri.toString() .startsWith("content://com.google.android.gallery3d")) ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME) : cursor.getColumnIndex(MediaStore.MediaColumns.DATA); // Picasa images on API 13+ if (columnIndex != -1) { filePath = cursor.getString(columnIndex); } } } catch (IllegalArgumentException e) { // Google Drive images return getFromMediaUriPfd(context, resolver, uri); } catch (SecurityException ignored) { // Nothing we can do } finally { if (cursor != null) cursor.close(); } } if (!TextUtils.isEmpty(filePath)) { return new File(filePath); } } return null; }
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 w w .j av a 2 s .c om*/ * @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. * @author paulburke */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { if (DEBUG) DatabaseUtils.dumpCursor(cursor); final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } catch (IllegalArgumentException ex) { Log.i(TAG, "getDataColumn: _data", ex); } finally { if (cursor != null) cursor.close(); } return null; }