How do I get the URI of a file saved with FileOutputStream?

Here's the code that saves the image file ... somewhere? How do I get the URI for the "webimage" file?

Bitmap bmp = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
        String fileName = "webImage";//no .png or .jpg needed
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
            FileOutputStream fo = openFileOutput(fileName, Context.MODE_PRIVATE);
            fo.write(bytes.toByteArray());
            // remember close file output
            fo.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

      

+3


source to share


3 answers


Use getFileStreamPath () like this:



String fileName = "webImage";
//...
Uri uri = Uri.fromFile(getFileStreamPath(fileName));

      

+4


source


I thought, I think:



final File file = new File(getFilesDir(), "webImage");
Uri weburi = Uri.fromFile(file);

      

+2


source


You can use Uri.fromFile(imageFile)

where imageFile

is an instanceFile

0


source







All Articles