List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
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 w w . j a va 2 s.com*/ 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.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {/*from w ww.j a va 2 s .c om*/ 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); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
static TaskList loadRemoteListFromDB(final Context context, final GoogleTaskList remoteList) { if (remoteList.dbid == null || remoteList.dbid < 1) return null; final Cursor c = context.getContentResolver().query(TaskList.getUri(remoteList.dbid), TaskList.Columns.FIELDS, null, null, null); TaskList tl = null;/*from w w w. j a v a 2 s .c o m*/ try { if (c.moveToFirst()) { tl = new TaskList(c); } } finally { if (c != null) c.close(); } return tl; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static String getStringField(Uri uri, String columnName) { String result = null;//from w w w . j a va 2 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:com.zzl.zl_app.cache.Utility.java
/** * Get a HttpClient object which is setting correctly . * /*from ww w .j a v a 2s . 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); WifiInfo info = wifiManager.getConnectionInfo(); if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) { // ??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:curso.android.DAO.RespostaDAO.java
public static List<Resposta> getRespostaPergunta(Pergunta p) { Cursor cursor = null; try {//from w ww . jav a2 s .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:com.dongfang.dicos.sina.UtilSina.java
public static HttpClient getNewHttpClient(Context context) { try {/*ww w. j a v a2 s . c om*/ 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, UtilSina.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, UtilSina.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:ro.weednet.contactssync.platform.ContactManager.java
private static long lookupRawContact(ContentResolver resolver, Account account, String serverContactId) { long rawContactId = 0; final Cursor c = resolver.query(UserIdQuery.CONTENT_URI, UserIdQuery.PROJECTION, UserIdQuery.SELECTION, new String[] { account.name, account.type, serverContactId }, null); try {//from w w w . java2s .c o m if ((c != null) && c.moveToFirst()) { rawContactId = c.getLong(UserIdQuery.COLUMN_RAW_CONTACT_ID); } } finally { if (c != null) { c.close(); } } return rawContactId; }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
static Task loadRemoteTaskFromDB(final Context context, final GoogleTask remoteTask) { final Cursor c = context.getContentResolver().query(Task.URI, Task.Columns.FIELDS, remoteTask.getTaskWithRemoteClause(), remoteTask.getTaskWithRemoteArgs(), null); Task t = null;//www . j a v a 2s . c om try { if (c.moveToFirst()) { t = new Task(c); } } finally { if (c != null) c.close(); } return t; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Set<Integer> getRootNodeIds() { Set<Integer> ids = new TreeSet<Integer>(); final String[] projection = new String[] { Nodes._ID }; final String selection = Nodes.NODE_PARENT_PATH + " IS NULL"; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, null, null); try {//w ww . j a va 2s . c om if (c.moveToFirst()) { int id; do { id = c.getInt(c.getColumnIndex(Nodes._ID)); ids.add(id); } while (c.moveToNext()); } } finally { c.close(); } return ids; }