List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:net.smart_json_database.JSONEntity.java
public static JSONEntity loadFromCursor(Cursor c) throws JSONException { int col_id = c.getColumnIndex("json_uid"); int col_createDate = c.getColumnIndex("createDate"); int col_updateDate = c.getColumnIndex("updateDate"); int col_data = c.getColumnIndex("data"); int col_type = c.getColumnIndex("type"); JSONEntity entity = new JSONEntity(); entity.setUid(c.getInt(col_id));/*w ww . j a v a 2s .c o m*/ entity.setCreationDate(Util.ParseDateFromString(c.getString(col_createDate))); entity.setUpdateDate(Util.ParseDateFromString(c.getString(col_updateDate))); entity.setData(new JSONObject(c.getString(col_data))); entity.setType(c.getString(col_type)); return entity; }
From source file:it.feio.android.omninotes.utils.StorageManager.java
public static String getRealPathFromURI(Context mContext, Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = null; try {//from w w w . j a v a2s.c o m mContext.getContentResolver().query(contentUri, proj, null, null, null); } catch (Exception e) { } if (cursor == null) { return null; } int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
From source file:org.opendatakit.common.android.utilities.ODKCursorUtils.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 whatever * data type it is.//from w w w . j a v a2 s . c o m * <p> * This does not actually convert data types from one type to the other. * Instead, it safely preserves null values and returns boxed data values. If * you specify ArrayList or HashMap, it JSON deserializes the value into one * of those. * * @param c * @param clazz * @param i * @return */ @SuppressWarnings("unchecked") public static final <T> T getIndexAsType(Cursor c, Class<T> clazz, int i) { // If you add additional return types here be sure to modify the javadoc. try { if (i == -1) return null; if (c.isNull(i)) { return null; } if (clazz == Long.class) { Long l = c.getLong(i); return (T) l; } else if (clazz == Integer.class) { Integer l = c.getInt(i); return (T) l; } else if (clazz == Double.class) { Double d = c.getDouble(i); return (T) d; } else if (clazz == String.class) { String str = c.getString(i); return (T) str; } else if (clazz == Boolean.class) { // stored as integers Integer l = c.getInt(i); return (T) Boolean.valueOf(l != 0); } else if (clazz == ArrayList.class) { // json deserialization of an array String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, ArrayList.class); } else if (clazz == HashMap.class) { // json deserialization of an object String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, HashMap.class); } else { throw new IllegalStateException("Unexpected data type in SQLite table"); } } catch (ClassCastException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " in SQLite table "); } catch (JsonParseException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (JsonMappingException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } }
From source file:com.popcorntime.apps.remote.utils.Utils.java
public static String getRealPathFromUri(Context context, Uri contentUri) { Log.i("uri", contentUri.toString()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { Cursor cursor = null; try {//from w ww . j a va2s . c o 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(); } } } else { Uri uri = contentUri; // DocumentProvider if (DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } // TODO handle non-primary volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri2 = ContentUris .withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri2, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri2 = null; if ("image".equals(type)) { contentUri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { //contentUri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { //contentUri2 = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri2, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; } }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static String getStringField(Uri uri, String columnName) { String result = null;/* w w w . j a v a2 s .c o m*/ final String[] projection = new String[] { columnName }; final Cursor c = sResolver.query(uri, projection, null, null, null); try { if (c.moveToFirst()) { result = c.getString(c.getColumnIndex(columnName)); } } finally { c.close(); } return result; }
From source file:curso.android.DAO.PerguntaDAO.java
public static Pergunta getPerguntaById(Pergunta p) { Cursor cursor = null; try {/* ww w. j a v a 2s. co m*/ cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE ask_id = " + p.getAsk_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nomeIndex = cursor.getColumnIndex("user_nome"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nomeIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); return ask; } while (!cursor.isAfterLast()); } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
/** * Convert image uri to file/*from w ww . ja v a 2s. c o 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:com.fada.sellsteward.myweibo.sina.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * //from ww w . j av a2s. c o m * @param context * : context of activity * @return HttpClient: HttpClient object */ public static HttpClient getHttpClient(Context context) { BasicHttpParams httpParameters = new BasicHttpParams(); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(httpParameters, Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParameters, Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(httpParameters); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { // ??APN Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.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) { HttpHost proxy = new HttpHost(proxyStr, 80); client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } mCursor.close(); } } return client; }
From source file:edu.mit.mobile.android.locast.data.JsonSyncableItem.java
/** * Gets a list for the current item in the cursor. * * @param column column number//w w w . j ava 2s . co m * @param c cursor pointing to a row * @return */ public static List<String> getList(int column, Cursor c) { final String t = c.getString(column); return getList(t); }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static List<RawContact> getLocalContacts(Context context, Uri uri) { Log.i(TAG, "*** Looking for local contacts"); List<RawContact> localContacts = new ArrayList<RawContact>(); final ContentResolver resolver = context.getContentResolver(); final Cursor c = resolver.query(uri, new String[] { Contacts._ID, RawContacts.SOURCE_ID }, null, null, null);/*w w w. jav a2s . c om*/ try { while (c.moveToNext()) { final long rawContactId = c.getLong(0); final String serverContactId = c.getString(1); RawContact rawContact = RawContact.create(rawContactId, serverContactId); localContacts.add(rawContact); } } finally { if (c != null) { c.close(); } } Log.i(TAG, "*** ... found " + localContacts.size()); return localContacts; }