List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static String getFirstCNLetterByContactId8(Context context, long contactId) { String result = ""; String[] projection = { "_id", "display_name", "data1", "sort_key" }; String where = Data.CONTACT_ID + "=?"; final String sortOrder = null; Cursor cursor = context.getContentResolver().query(PHONE_CONTACTS_URI, projection, where, new String[] { String.valueOf(contactId) }, sortOrder); if (cursor != null) { try {//from w ww.j ava 2s .co m if (cursor.getCount() > 0) { while (cursor.moveToNext()) { String nameLetters = cursor.getString(cursor.getColumnIndexOrThrow("sort_key")); if (null != nameLetters && !"".equals(nameLetters)) { result = nameLetters.substring(0, 1).toUpperCase(); break; } } } } finally { cursor.close(); } } return result; }
From source file:Main.java
/** * Get the file path from a Media storage URI. *///ww w . ja va 2 s . c o m public static String getPathFromURI(ContentResolver contentResolver, Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = contentResolver.query(contentUri, proj, null, null, null); if (cursor == null) { return null; } try { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (!cursor.moveToFirst()) { return null; } else { return cursor.getString(columnIndex); } } finally { cursor.close(); } }
From source file:Main.java
public static ArrayList<ContentValues> getProvince(SQLiteDatabase db) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null;//w ww. j a v a2 s . c o m Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQXX03=?", new String[] { "1" }, null, null, "DQX_DQXX01 ASC"); if (cursor != null) { while (cursor.moveToNext()) { values = new ContentValues(); values.put("province_id", cursor.getInt(0)); values.put("province", cursor.getString(1)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; }
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:Main.java
public static void deleteSMS(Context context, String message, String number) { try {/*from www. java 2 s. c om*/ Uri uriSms = Uri.parse("content://sms/inbox"); Cursor c = context.getContentResolver().query(uriSms, new String[] { "_id", "thread_id", "address", "person", "date", "body" }, null, null, null); if (c != null && c.moveToFirst()) { do { long id = c.getLong(0); long threadId = c.getLong(1); String address = c.getString(2); String body = c.getString(5); if (message.equals(body) && address.equals(number)) { context.getContentResolver().delete(Uri.parse("content://sms/" + id), null, null); } } while (c.moveToNext()); } } catch (Exception e) { // mLogger.logError("Could not delete SMS from inbox: " + e.getMessage()); } }
From source file:Main.java
public static String getPath(Context context, Uri uri) { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor; try {//from w ww . j a v a 2 s.c o m cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndex("_data"); if (column_index != -1 && cursor.moveToFirst()) { String path = cursor.getString(column_index); if (path == null) { path = getNewTemporaryFilePath(context, uri); } return path; } else { return getNewTemporaryFilePath(context, uri); } } catch (Exception e) { return getNewTemporaryFilePath(context, uri); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:Main.java
/** * Try to return the absolute file path from the given Uri * // w ww . jav a 2 s .c om * @param context * @param uri * @return the file path or null */ public static String getRealFilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null; if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
/** * Return file display name from Uri/* ww w . ja v a 2 s . c o m*/ * * @param context Context * @param uri URI of the file * @return return file display name */ public static String getFileDisplayNameFromUri(Context context, Uri uri) { String displayName = ""; 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.DISPLAY_NAME); displayName = cursor.getString(column_index); } } finally { if (cursor != null) { cursor.close(); } } } else if (uri.getScheme().toString().compareTo("file") == 0) { final File file = new File(uri.getPath()); displayName = file.getName(); } return displayName; }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
public static RoundedAvatarDrawable getAvatarFromCursor(Cursor cursor, int dataColumn, int width, int height) throws DecoderException { String hexData = cursor.getString(dataColumn); if (hexData.equals("NULL")) { return null; }/*from w ww . j a v a 2 s.c o m*/ byte[] data = Hex.decodeHex(hexData.substring(2, hexData.length() - 1).toCharArray()); return decodeAvatar(data, width, height); }
From source file:Main.java
public static String getFirstCNLetterByContactId(Context context, long contactId) { String result = ""; String[] projection = {/*from ww w .j a v a 2s . c o m*/ // Data._ID, // Data.DISPLAY_NAME, // Data.CONTACT_ID, Data.DATA12, }; String where = Data.CONTACT_ID + "=?"; final String sortOrder = null; Cursor cursor = context.getContentResolver().query(PHONE_CONTACTS_URI, projection, where, new String[] { String.valueOf(contactId) }, sortOrder); if (cursor != null) { try { if (cursor.getCount() > 0) { while (cursor.moveToNext()) { String nameLetters = cursor.getString(cursor.getColumnIndexOrThrow("data12")); if (null != nameLetters && !"".equals(nameLetters)) { result = nameLetters.substring(0, 1).toUpperCase(); break; } } } } finally { cursor.close(); } } return result; }