Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert real path format to Uri in android

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

like image 683
yoga Avatar asked Aug 28 '12 14:08

yoga


1 Answers

Try this:

Uri.fromFile(new File("/sdcard/cats.jpg"));
like image 76
dragostis Avatar answered Oct 03 '22 23:10

dragostis