List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:Main.java
public static String getRealPathFromURI(Uri uri, Context context) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); cursor.moveToFirst();/* w w w . jav a2 s. c om*/ int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); return cursor.getString(idx); }
From source file:com.codebutler.farebot.key.CardKeys.java
private static CardKeys fromCursor(Cursor cursor) throws JSONException { String cardType = cursor.getString(cursor.getColumnIndex(KeysTableColumns.CARD_TYPE)); String keyData = cursor.getString(cursor.getColumnIndex(KeysTableColumns.KEY_DATA)); JSONObject keyJSON = new JSONObject(keyData); if (cardType.equals("MifareClassic")) { return ClassicCardKeys.fromJSON(keyJSON); }// www.j av a2 s. c o m throw new IllegalArgumentException("Unknown card type for key: " + cardType); }
From source file:Main.java
public static boolean isTableExists(SQLiteDatabase db, String tableName) { String sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? "; String paras[] = { tableName }; try {/*from ww w .jav a 2 s . c o m*/ Cursor cursor = db.rawQuery(sql, paras); cursor.moveToNext(); String name = cursor.getString(cursor.getColumnIndex("name")); if (name.equals(tableName)) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
public static int getCursorInt(Cursor cursor, String name) { if (isCursorEmpty(cursor)) { return 0; } else {/*from w ww . jav a 2 s . c o m*/ return cursor.getInt(cursor.getColumnIndex(name)); } }
From source file:Main.java
public static float getCursorFloat(Cursor cursor, String name) { if (isCursorEmpty(cursor)) { return 0; } else {//from w ww . ja va2s . c om return cursor.getFloat(cursor.getColumnIndex(name)); } }
From source file:Main.java
public static String getCursorString(Cursor cursor, String name) { if (isCursorEmpty(cursor)) { return ""; } else {//from www.j a va2 s . c o m return cursor.getString(cursor.getColumnIndex(name)); } }
From source file:Main.java
/** * Helper method to reslove a uri into a path. * // w w w . j av a2 s . co m * @param contentURI * a uri path * @return the path as a string */ public static String getRealPathFromURI(Uri contentURI, Context context) { Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); String path = cursor.getString(idx); cursor.close(); return path; }
From source file:Main.java
public static void bindText(View view, Cursor cursor, int resource, String column) { TextView textView = (TextView) view.findViewById(resource); textView.setText(cursor.getString(cursor.getColumnIndex(column))); }
From source file:io.trigger.forge.android.modules.contprov.API.java
private static JSONArray extractNotesFromCursor(Cursor c) throws JSONException { JSONArray toRet = new JSONArray(); int[] cIndices = new int[] { c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_2_catname), c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_3_catstatus) }; for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {//Extract note from cursor JSONObject o = new JSONObject(); o.put("name", c.getString(cIndices[0])); o.put("status", c.getString(cIndices[1])); //c.getString(cIndices[SERVER_ID]), toRet.put(o);// ww w.jav a 2 s . c o m } return toRet; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentURI) { String result = null;// w w w .ja va2 s . c o m Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; }