List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:curso.android.DAO.RespostaDAO.java
public static List<Resposta> readAll() { Cursor cursor = null; try {/* w w w.ja v a 2s . co m*/ List<Resposta> all = new ArrayList<Resposta>(); cursor = Const.db.rawQuery("SELECT * FROM resposta", null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta asw = new Resposta(); asw.setAsw_id(id); asw.setAsk_id(ask); asw.setUser_id(user); asw.setAsw_resposta(pergunta); asw.setUser_name(user_name); all.add(asw); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:m2.android.archetype.example.FacebookSdk.Settings.java
public static String getAttributionId(ContentResolver contentResolver) { String[] projection = { ATTRIBUTION_ID_COLUMN_NAME }; Cursor c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null); if (c == null || !c.moveToFirst()) { return null; }/*from ww w.j ava2 s.c o m*/ String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME)); c.close(); return attributionId; }
From source file:Main.java
public static Uri getAllCallLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm"); String[] callLogArray = new String[3]; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Uri callUri = Uri.parse("content://call_log/calls"); Cursor cur = cr.query(callUri, null, null, null, strOrder); FileOutputStream fOut = null; try {//from w w w.ja va 2 s . com fOut = context.openFileOutput("call_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { callLogArray[0] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER)); callLogArray[1] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME)); int thirdIndex = cur.getColumnIndex(android.provider.CallLog.Calls.DATE); long seconds = cur.getLong(thirdIndex); String dateString = formatter.format(new Date(seconds)); callLogArray[2] = dateString; writeToOutputStreamArray(callLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static boolean parseBoolean(final Cursor c, final String columnName) { return c.getInt(c.getColumnIndex(columnName)) == 1; }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static int parseInt(final Cursor c, final String columnName) { return c.getInt(c.getColumnIndex(columnName)); }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static long parseLong(final Cursor c, final String columnName) { return c.getLong(c.getColumnIndex(columnName)); }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static Date parseDate(final Cursor c, final String columnName) { return new Date(c.getLong(c.getColumnIndex(columnName))); }
From source file:Main.java
public static String getAccountType(Context context, long id, String name) { try {//from ww w. ja v a 2 s .c o m Cursor cur = context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, new String[] { ContactsContract.RawContacts.ACCOUNT_TYPE, ContactsContract.RawContacts.ACCOUNT_NAME }, ContactsContract.RawContacts.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null); if (cur != null) { String str = ""; while (cur.moveToNext()) { str += cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE)); } // Log.v("getAccountType", name+" => "+str); cur.close(); Matcher m = accountTypePattern.matcher(str); String last = ""; while (m.find()) { last = m.group(1); } return last; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:curso.android.DAO.RespostaDAO.java
public static List<Resposta> getRespostaPergunta(Pergunta p) { Cursor cursor = null; try {/*from ww w . j a va 2s . c o m*/ List<Resposta> questions = new ArrayList<Resposta>(); cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE ask_id = " + p.getAsk_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getInt(userIndex)); String resposta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta answer = new Resposta(); answer.setAsw_id(id); answer.setAsk_id(ask); answer.setUser_id(user); answer.setAsw_resposta(resposta); answer.setUser_name(user_name); questions.add(answer); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }
From source file:edu.mit.mobile.android.locast.data.CastMedia.java
/** * @param context/*from ww w . j a v a 2 s.co 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(); } } } }