List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static File getRealFileFromURI(Context context, Uri contentUri) { Cursor cursor = null; try {// w w w. j a va 2 s. c om 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(); String path = cursor.getString(column_index); return new File(path); } finally { if (cursor != null) { cursor.close(); } } }
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();/* www . j av a 2 s. c o m*/ result = "external".equals(cursor.getString(0)); } cursor.close(); } return result; }
From source file:Main.java
/** * Return the data stored in the cursor at the given index and given position * (ie the given row which the cursor is currently on) as null OR a String. * <p>//from ww w . j a v a 2 s . c o m * NB: Currently only checks for Strings, long, int, and double. * * @param c * @param i * @return */ @SuppressLint("NewApi") public static String getIndexAsString(Cursor c, int i) { // If you add additional return types here be sure to modify the javadoc. if (i == -1) return null; if (c.isNull(i)) { return null; } switch (c.getType(i)) { case Cursor.FIELD_TYPE_STRING: return c.getString(i); case Cursor.FIELD_TYPE_FLOAT: { // the static version of this seems to have problems... Double d = c.getDouble(i); String v = d.toString(); return v; } case Cursor.FIELD_TYPE_INTEGER: { // the static version of this seems to have problems... Long l = c.getLong(i); String v = l.toString(); return v; } case Cursor.FIELD_TYPE_NULL: return c.getString(i); default: case Cursor.FIELD_TYPE_BLOB: throw new IllegalStateException("Unexpected data type in SQLite table"); } }
From source file:Main.java
public static String getRealPathByUri(Context context, Uri uri) { if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { return uri.getPath(); }/* w w w . jav a 2s .com*/ try { ContentResolver resolver = context.getContentResolver(); String[] proj = new String[] { MediaStore.Images.Media.DATA }; Cursor cursor = MediaStore.Images.Media.query(resolver, uri, proj); String realPath = null; if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { realPath = cursor.getString(columnIndex); } cursor.close(); } return realPath; } catch (Exception e) { return uri.getPath(); } }
From source file:Main.java
/** * Method to resolve the display name of a content URI. * * @param uri the content URI to be resolved. * @param contentResolver the content resolver to query. * @param columnField the column field to query. * @return the display name of the @code uri if present in the database * or an empty string otherwise./*from w ww.j a v a2 s . c om*/ */ public static String getDisplayName(Uri uri, ContentResolver contentResolver, String columnField) { if (contentResolver == null || uri == null) return ""; Cursor cursor = null; try { cursor = contentResolver.query(uri, null, null, null, null); if (cursor != null && cursor.getCount() >= 1) { cursor.moveToFirst(); int index = cursor.getColumnIndex(columnField); if (index > -1) return cursor.getString(index); } } catch (NullPointerException e) { // Some android models don't handle the provider call correctly. // see crbug.com/345393 return ""; } finally { if (cursor != null) cursor.close(); } return ""; }
From source file:fr.mixit.android.utils.SyncUtils.java
public static String getLocalMd5(ContentResolver resolver, String url) { final String syncId = MixItContract.Sync.generateSyncId(url); final Uri uri = MixItContract.Sync.buildSyncUri(syncId); Cursor cursor = resolver.query(uri, SyncQuery.PROJECTION, null, null, null); try {//w w w .jav a 2s.co m if (!cursor.moveToFirst()) return ""; return cursor.getString(SyncQuery.MD5); } finally { cursor.close(); } }
From source file:Main.java
public static Map<String, Integer> getCity(SQLiteDatabase db, String tableName, int dqx_dqxx01, boolean municipalities) { Map<String, Integer> cityMap = new LinkedHashMap<String, Integer>(); Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext();/*from w w w . j a va 2 s. c o m*/ } while (cursor.moveToNext()) { cityMap.put(cursor.getString(0), cursor.getInt(1)); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return cityMap; }
From source file:fr.mixit.android.io.JsonHandlerApplyInterests.java
private static boolean isItemUpdated(Uri uri, JSONObject item, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, MixItContract.Interests.PROJ.PROJECTION, null, null, null); try {//from w ww .j a va 2 s . c o m if (!cursor.moveToFirst()) { return false; } final String curName = cursor.getString(MixItContract.Interests.PROJ.NAME) .toLowerCase(Locale.getDefault()).trim(); final String newName = item.has(TAG_NAME) ? item.getString(TAG_NAME).toLowerCase(Locale.getDefault()).trim() : curName; return !curName.equals(newName); } finally { if (cursor != null) { cursor.close(); } } }
From source file:fr.mixit.android.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 w w w .jav a2s . com*/ 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 curLinkedIn = cursor.getString(SpeakersQuery.LINKEDIN).toLowerCase().trim(); final String curTwitter = cursor.getString(SpeakersQuery.TWITTER).toLowerCase().trim(); final String curBlog = cursor.getString(SpeakersQuery.BLOG).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; final String newLinkedIn = speaker.has("linkedin") ? speaker.getString("linkedin").toLowerCase().trim() : curLinkedIn; final String newTwitter = speaker.has("twitter") ? speaker.getString("twitter").toLowerCase().trim() : curTwitter; final String newBlog = speaker.has("blog") ? speaker.getString("blog").toLowerCase().trim() : curBlog; return (!curFirstName.equals(newFirstName) || !curLastName.equals(newLastName) || !curBio.equals(newBio) || !curCompany.equals(newCompany) || !curLinkedIn.equals(newLinkedIn) || !curTwitter.equals(newTwitter) || !curBlog.equals(newBlog)); } finally { cursor.close(); } }
From source file:cn.edu.mju.Thriphoto.net.NetStateManager.java
/** * ?? APN {@link org.apache.http.HttpHost} * * @return {@link org.apache.http.HttpHost} *//*w w w . j av a2s . c om*/ public static HttpHost getAPN() { HttpHost proxy = null; Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = null; if (null != mContext) { mCursor = mContext.getContentResolver().query(uri, null, null, null, null); } if (mCursor != null && mCursor.moveToFirst()) { // ??? String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); if (proxyStr != null && proxyStr.trim().length() > 0) { proxy = new HttpHost(proxyStr, 80); } mCursor.close(); } return proxy; }