List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
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); }/*from ww w.ja v a 2 s .co m*/ } return imagePath; }
From source file:Main.java
/** * Utils to get File path//from w w w . j a va 2 s .c o m * * @param uri * @return */ public static String getPath(Context context, Uri uri) { String scheme = uri.getScheme(); String s = null; if (scheme.equals("content")) { String[] projection = { MediaStore.Files.FileColumns.DATA }; Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA); cursor.moveToFirst(); s = cursor.getString(columnIndex); } else if (scheme.equals("file")) { s = uri.getPath(); } // Log.d("ActionManager", "URI:" + uri + " - S:" + s); return s; }
From source file:Main.java
/** * Find a download with the specified name. Returns -1 if none was * found./* w w w. ja va 2 s . c om*/ */ static long findPath(DownloadManager dm, String path) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); Cursor c = dm.query(query); if (!c.moveToFirst()) return -1; final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID); final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI); do { final String uri = c.getString(columnLocalURI); if (uri != null && uri.endsWith(path)) return c.getLong(columnID); } while (c.moveToNext()); return -1; }
From source file:Main.java
public static String getPath(Activity activity, Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();//ww w. j ava 2 s .com return cursor.getString(column_index); }
From source file:Main.java
public static String getVideoPath(Activity activity, Uri uri) { String[] projection = { MediaStore.Video.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst();//from w w w. j a va 2 s .c o m return cursor.getString(column_index); }
From source file:Main.java
public static File parseFileByIntentData(Context context, Intent data) { File file = null;// w ww . j a v a2 s. co m if (data != null && data.getData() != null) { String[] proj = { MediaStore.Images.Media.DATA }; CursorLoader cursorLoader = new CursorLoader(context, data.getData(), proj, null, null, null); Cursor cursor = null; try { cursor = cursorLoader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); file = new File(cursor.getString(column_index)); } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } } return file; }
From source file:Main.java
public static String geVideotName(Activity activity, Uri uri) throws Exception { String[] projection = { MediaStore.Video.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst();/*from w w w . j a v a 2 s . c o m*/ Uri filePathUri = Uri.parse(cursor.getString(column_index)); String file_name = filePathUri.getLastPathSegment().toString(); return file_name; }
From source file:Main.java
public static String getName(Activity activity, Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();// w ww. ja v a2 s. c om Uri filePathUri = Uri.parse(cursor.getString(column_index)); String file_name = filePathUri.getLastPathSegment().toString(); return file_name; }
From source file:Main.java
private static long getFileId(Context context, Uri fileUri) { Cursor cursor = context.getContentResolver().query(fileUri, mediaColumns, null, null, null); if (cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID); int id = cursor.getInt(columnIndex); return id; }/*from w w w . j av a 2 s . c om*/ return 0; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentUri) { String res = null;/*www. j av a 2s .c om*/ String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); res = cursor.getString(column_index); } cursor.close(); return res; }