List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static String getRealPathFromURI(Uri contentUri, Context ctx) { String[] proj = { MediaStore.Video.Media.DATA }; Cursor cursor = ((Activity) ctx).managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst();// w w w . j a va 2s .com String ret = cursor.getString(columnIndex); return ret; } else { return contentUri.getPath(); } }
From source file:com.facebook.Settings.java
/** * Acquire the current attribution id from the facebook app. * @return returns null if the facebook app is not present on the phone. *//*w w w .j av a 2 s .c o m*/ public static String getAttributionId(ContentResolver contentResolver) { Cursor c = null; try { String[] projection = { ATTRIBUTION_ID_COLUMN_NAME }; c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null); if (c == null || !c.moveToFirst()) { return null; } String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME)); return attributionId; } catch (Exception e) { Log.d(TAG, "Caught unexpected exception in getAttributionId(): " + e.toString()); return null; } finally { if (c != null) { c.close(); } } }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static String getStringField(String resourcePath, String columnName) { String result = null;//from w w w .j av a 2 s .co m final String[] projection = new String[] { columnName }; final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, sSelection, selectionArgs, null); try { if (c.moveToFirst()) { result = c.getString(c.getColumnIndex(columnName)); } } finally { c.close(); } return result; }
From source file:fr.mixit.android.io.JsonHandlerApplyMembers.java
private static boolean isSharedLinkUpdated(Uri uri, String itemId, JSONObject sharedLink, ContentResolver resolver) throws JSONException { final String[] selectionArgs = { itemId }; final Cursor cursor = resolver.query(uri, MixItContract.SharedLinks.PROJ.PROJECTION, MixItContract.SharedLinks.MEMBER_ID + " = ?", selectionArgs, null); try {// ww w . ja v a 2 s .c o m if (!cursor.moveToFirst()) { return false; } final int curOrderNum = cursor.getInt(MixItContract.SharedLinks.PROJ.ORDER_NUM); final String curName = cursor.getString(MixItContract.SharedLinks.PROJ.NAME) .toLowerCase(Locale.getDefault()).trim(); final String curUrl = cursor.getString(MixItContract.SharedLinks.PROJ.URL) .toLowerCase(Locale.getDefault()).trim(); final int newOrderNum = sharedLink.has(TAG_ORDER_NUM) ? sharedLink.getInt(TAG_ORDER_NUM) : curOrderNum; final String newName = sharedLink.has(TAG_NAME) ? sharedLink.getString(TAG_NAME).toLowerCase(Locale.getDefault()).trim() : curName; final String newUrl = sharedLink.has(TAG_URL) ? sharedLink.getString(TAG_URL).toLowerCase(Locale.getDefault()).trim() : curUrl; return !curName.equals(newName) || // !curUrl.equals(newUrl) || // curOrderNum != newOrderNum; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
/** * Retourner le nom de calendrier/* w w w.j av a 2 s . co m*/ * * @param id * @return */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static String getCalendarName(ContentResolver contentResolver, String id) { String name = null; Cursor cursor; String[] projection; Uri calendarUri; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { calendarUri = CalendarContract.Calendars.CONTENT_URI; projection = new String[] { CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME }; } else if (Integer.parseInt(Build.VERSION.SDK) >= 8) { calendarUri = Uri.parse("content://com.android.calendar/calendars"); projection = new String[] { "_id", "displayname" }; } else { calendarUri = Uri.parse("content://calendar/calendars"); projection = new String[] { "_id", "displayname" }; } cursor = contentResolver.query(calendarUri, projection, "_id = ?", new String[] { id }, null); if (cursor.moveToFirst()) { name = cursor.getString(1); } cursor.close(); return name; }
From source file:com.fada.sellsteward.myweibo.sina.net.Utility.java
public static HttpClient getNewHttpClient(Context context) { try {/*from ww w. ja va 2 s.c o m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(params, Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(ccm, params); 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; } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static String getPublicUrl(final String resourcePath) { final String[] projection = new String[] { Nodes.NODE_PUBLIC_URL }; final String selection = Nodes.NODE_RESOURCE_PATH + "=?"; final String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); String url = null;//w ww . j a va 2 s. c o m try { if (c.moveToFirst()) { url = c.getString(c.getColumnIndex(Nodes.NODE_PUBLIC_URL)); } } finally { c.close(); } return TextUtils.isEmpty(url) ? null : url; }
From source file:curso.android.DAO.RespostaDAO.java
public static Resposta getPerguntaById(Resposta p) { Cursor cursor = null; try {/*from w w w . j a v a 2 s. c om*/ cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE asw_id = " + p.getAsw_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.getString(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); return answer; } while (!cursor.isAfterLast()); } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:za.co.neilson.alarm.database.Database.java
public static List<Alarm> getAll() { List<Alarm> alarms = new ArrayList<Alarm>(); Cursor cursor = Database.getCursor(); if (cursor.moveToFirst()) { do {//w ww . j av a 2s.c o m // COLUMN_ALARM_ID, // COLUMN_ALARM_ACTIVE, // COLUMN_ALARM_TIME, // COLUMN_ALARM_DAYS, // COLUMN_ALARM_DIFFICULTY, // COLUMN_ALARM_TONE, // COLUMN_ALARM_VIBRATE, // COLUMN_ALARM_NAME Alarm alarm = new Alarm(); alarm.setId(cursor.getInt(0)); alarm.setAlarmActive(cursor.getInt(1) == 1); alarm.setAlarmTime(cursor.getString(2)); byte[] repeatDaysBytes = cursor.getBlob(3); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(repeatDaysBytes); try { ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Alarm.Day[] repeatDays; Object object = objectInputStream.readObject(); if (object instanceof Alarm.Day[]) { repeatDays = (Alarm.Day[]) object; alarm.setDays(repeatDays); } } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } alarm.setDifficulty(Difficulty.values()[cursor.getInt(4)]); alarm.setAlarmTonePath(cursor.getString(5)); alarm.setVibrate(cursor.getInt(6) == 1); alarm.setAlarmName(cursor.getString(7)); alarms.add(alarm); } while (cursor.moveToNext()); } cursor.close(); return alarms; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static boolean isDirectory(long id) { String[] projection = new String[] { Nodes.NODE_KIND }; String selection = Nodes._ID + "=?"; String[] selectionArgs = new String[] { String.valueOf(id) }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); String type = null;//from www.j ava2 s .co m try { if (c.moveToFirst()) { type = c.getString(c.getColumnIndex(Nodes.NODE_KIND)); } } finally { c.close(); } return (type != null) ? U1NodeKind.DIRECTORY == U1NodeKind.valueOf(type.toUpperCase(Locale.US)) : false; }