[Java]View PlainCopy
- Private String Getrealpathfromuri (Uri Contenturi) {
- cursor cursor = null;
- String result = Contenturi.tostring ();
- String[] proj = {MediaStore.Images.Media.DATA};
- cursor = Managedquery (Contenturi, proj, null, null, null );
- if (cursor = = null) throw new NullPointerException ("Reader file field");
- if (cursor! = null) {
- int column_index = cursor
- . Getcolumnindexorthrow (MediaStore.Images.Media.DATA);
- Cursor.movetofirst ();
- //finally get Picture path based on index value
- result = Cursor.getstring (Column_index);
- Try
- {
- versions above//4.0 will be automatically closed (4.0--14;; 4.0.3--15)
- if (Integer.parseint (Build.VERSION.SDK) < )
- {
- Cursor.close ();
- }
- }catch (Exception e)
- {
- LOG.E (TAG, "error:" + E);
- }
- }
- return result;
- }
Path = path.substring (Path.indexof ("/sdcard"), Path.length ()); Directories do not write dead.
How to get a photo album on SDcard