List of usage examples for android.database Cursor getString
String getString(int columnIndex);
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 ww w .j av a 2 s . co 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:edu.mit.mobile.android.locast.data.CastMedia.java
/** * @param context// ww w . j a v a 2 s . c o m * @param c * @param castMediaUri * */ public static void showMedia(Context context, Cursor c, Uri castMediaUri) { final String mediaString = c.getString(c.getColumnIndex(CastMedia._MEDIA_URL)); final String locMediaString = c.getString(c.getColumnIndex(CastMedia._LOCAL_URI)); String mimeType = null; Uri media; if (locMediaString != null) { media = Uri.parse(locMediaString); if ("file".equals(media.getScheme())) { mimeType = c.getString(c.getColumnIndex(CastMedia._MIME_TYPE)); } } else if (mediaString != null) { media = Uri.parse(mediaString); mimeType = c.getString(c.getColumnIndex(CastMedia._MIME_TYPE)); // we strip this because we don't really want to force them to go to the browser. if ("text/html".equals(mimeType)) { mimeType = null; } } else { Log.e(TAG, "asked to show media for " + castMediaUri + " but there was nothing to show"); return; } final Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(media, mimeType); if (mimeType != null && mimeType.startsWith("video/")) { context.startActivity(new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(castMediaUri, c.getLong(c.getColumnIndex(CastMedia._ID))))); } else { // setting the MIME type for URLs doesn't work. try { context.startActivity(i); } catch (final ActivityNotFoundException e) { // try it again, but without a mime type. if (mimeType != null) { i.setDataAndType(media, null); } try { context.startActivity(i); } catch (final ActivityNotFoundException e2) { Toast.makeText(context, R.string.error_cast_media_no_activities, Toast.LENGTH_LONG).show(); } } } }
From source file:Main.java
public static String getRealFilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null;//from w w w . j a v a 2s. c o m 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[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
public static Map<Integer, List> getAreaByPid(int id, File file) { String sql = "select area,areaid from area where cityid= " + id; SQLiteDatabase db = null;/* w w w .j av a 2s. c om*/ Cursor c = null; List<String> areaList = null; List areaIdList = null; Map<Integer, List> areaData = new HashMap<Integer, List>(); try { db = SQLiteDatabase.openOrCreateDatabase(file, null); c = db.rawQuery(sql, null); areaList = new ArrayList<String>(); areaIdList = new ArrayList<String>(); while (c.moveToNext()) { Map areaMap = new HashMap(); areaMap.put(c.getString(0), c.getInt(1)); areaList.add(c.getString(0)); areaIdList.add(areaMap); } areaData.put(0, areaList); areaData.put(1, areaIdList); } catch (Exception e) { Log.d("WineStock", "getAreaByPid:" + e.getMessage()); } finally { if (c != null) { c.close(); } if (db != null) { db.close(); } } return areaData; }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static String parseString(final Cursor c, final String columnName) { try {/* ww w. j av a2 s.c om*/ return c.getString(c.getColumnIndexOrThrow(columnName)); } catch (final IllegalArgumentException e) { if (AppContext.DEBUG) { e.printStackTrace(); } } return null; }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param c/* ww w.ja v a 2 s. c o m*/ * @return true if the authenticated user can change the item's privacy level. */ public static boolean canChangePrivacyLevel(Context context, Cursor c) { final String useruri = Authenticator.getUserUri(context); return useruri == null || useruri.equals(c.getString(c.getColumnIndex(_AUTHOR_URI))); }
From source file:com.android.dialer.calllog.ContactInfoHelper.java
/** * Returns the contact information stored in an entry of the call log. * * @param c A cursor pointing to an entry in the call log. *///from w w w.j av a 2s. c om public static ContactInfo getContactInfo(Cursor c) { ContactInfo info = new ContactInfo(); info.lookupUri = UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_LOOKUP_URI)); info.name = c.getString(CallLogQuery.CACHED_NAME); info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE); info.label = c.getString(CallLogQuery.CACHED_NUMBER_LABEL); String matchedNumber = c.getString(CallLogQuery.CACHED_MATCHED_NUMBER); info.number = matchedNumber == null ? c.getString(CallLogQuery.NUMBER) : matchedNumber; info.normalizedNumber = c.getString(CallLogQuery.CACHED_NORMALIZED_NUMBER); info.photoId = c.getLong(CallLogQuery.CACHED_PHOTO_ID); info.photoUri = UriUtils .nullForNonContactsUri(UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_PHOTO_URI))); info.formattedNumber = c.getString(CallLogQuery.CACHED_FORMATTED_NUMBER); return info; }
From source file:com.nextgis.mobile.map.Layer.java
protected static String getFileNameByUri(final Context context, Uri uri, String defaultName) { String fileName = defaultName; Uri filePathUri = uri;// ww w. j av a2 s. c o m try { if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA); //Instead of "MediaStore.Images.Media.DATA" can be used "_data" filePathUri = Uri.parse(cursor.getString(column_index)); fileName = filePathUri.getLastPathSegment().toString(); } } else if (uri.getScheme().compareTo("file") == 0) { fileName = filePathUri.getLastPathSegment().toString(); } else { fileName = fileName + "_" + filePathUri.getLastPathSegment(); } } catch (Exception e) { //do nothing, only return default file name; Log.d(TAG, e.getLocalizedMessage()); } return fileName; }
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
private static Quiz createFillBlankQuiz(Cursor cursor, String question, String answer, boolean solved) { final String start = cursor.getString(9); final String end = cursor.getString(10); return new FillBlankQuiz(question, answer, start, end, solved); }
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 a va 2 s.c o m*/ * @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()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } catch (Exception e) { return null; } finally { if (cursor != null) cursor.close(); } return null; }