9

for example

real path is mnt/sdcard/image_1.jpg Uri path is content://media/external/images/media/140 like this

  Uri photoUri =Uri.parse("content://media/external/images/media/140");
                                            Log.d("selectedphoto",""+photoUri);
               selectedImagePath = getPath(photoUri);

     public String getPath(Uri uri) {
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();



    return cursor.getString(column_index);
    }

In above code I convert Uri to real path but dnt know how to convert real path to Uri

Vishal Pawar
  • 4,324
  • 4
  • 28
  • 54
yoga
  • 131
  • 2
  • 2
  • 9

2 Answers2

14

Try this:

Uri.fromFile(new File("/sdcard/cats.jpg"));
dragostis
  • 2,574
  • 2
  • 20
  • 39
  • take picture using camera to store sdcard folder like mnt/sdcard/image.jpg i need to upload that picture into facebook using hackbook..gallery images are uploaded but camera images are not working......... – yoga Aug 29 '12 at 05:52
  • i have real path if it possible to convert the Uri path..have any idea please help me.....thanks – yoga Aug 29 '12 at 05:57
  • Works on samsung tab e – farhan patel May 11 '17 at 09:37
0

This will get the file path from the MediaProvider, DownloadsProvider, and ExternalStorageProvider, while falling back to the unofficial ContentProvider method you mention.

https://stackoverflow.com/a/27271131/3758898

Community
  • 1
  • 1
Kishan Vaghela
  • 7,678
  • 5
  • 42
  • 67