List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:Main.java
public static String getAbsoluteImagePath(Context context, Uri uri) { String imagePath = ""; Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { imagePath = cursor.getString(column_index); }//ww w . j a v a 2s. c om } return imagePath; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentURI) { String TAG = "PINGUINO-getRealPathFromURI"; String result;//from ww w. j a va 2s. co m Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { result = contentURI.getPath(); } else { Log.d(TAG, "cursor1:" + cursor); cursor.moveToFirst(); Log.d(TAG, "cursor2:" + cursor); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); Log.d(TAG, "idx:" + idx); result = cursor.getString(idx); Log.d(TAG, "result:" + result); cursor.close(); } return result; }
From source file:net.lamp.support.NetStateManager.java
/** * ?? APN ?{@link HttpHost} //from w ww .j a v a2 s . co m * * @return {@link HttpHost} */ public static HttpHost getAPN() { HttpHost proxy = null; Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = null; if (null != mContext) { mCursor = mContext.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) { proxy = new HttpHost(proxyStr, 80); } mCursor.close(); } return proxy; }
From source file:Main.java
private static String getRealPathFromURI(Context context, Uri contentURI) { String result;/* w w w . j ava2s .c om*/ Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { // Source is Dropbox or other similar local file path result = contentURI.getPath(); } else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; }
From source file:Main.java
public static Uri getAudioContentUri(Context context, File file) { String filePath = file.getAbsolutePath(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + "=?", new String[] { filePath }, null); cursor.moveToFirst(); int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/audio/media"); return Uri.withAppendedPath(baseUri, "" + id); }
From source file:cn.edu.mju.Thriphoto.net.NetStateManager.java
/** * ?? APN {@link org.apache.http.HttpHost} * * @return {@link org.apache.http.HttpHost} *///from ww w.ja v a 2s . co m public static HttpHost getAPN() { HttpHost proxy = null; Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = null; if (null != mContext) { mCursor = mContext.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) { proxy = new HttpHost(proxyStr, 80); } mCursor.close(); } return proxy; }
From source file:com.goliathonline.android.kegbot.io.RemoteTapHandler.java
private static ContentValues queryTapDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, TapsQuery.PROJECTION, null, null, null); try {//from ww w . j a v a 2 s. c o m if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(TapsQuery.UPDATED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:Main.java
/** * Try to return the absolute file path from the given Uri * * @param context//w ww . j a va 2 s . com * @param uri * @return the file path or null */ public static String uri2FilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null; if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
public static String getThumbnailPathFromURI(Uri contentUri, ContentResolver content_resolver) { String uri = ""; Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(content_resolver, ContentUris.parseId(contentUri), MediaStore.Images.Thumbnails.MINI_KIND, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst();//**EDIT** uri = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA)); }// ww w . j a va 2 s . c om return uri; }
From source file:Main.java
public static String getPath(Context context, Uri uri) { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try {// ww w . j a va 2 s . co m cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }