Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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();
        }
like image 568
Ethan Allen Avatar asked Jul 13 '15 17:07

Ethan Allen


2 Answers

Use getFileStreamPath() like this:

String fileName = "webImage";
//...
Uri uri = Uri.fromFile(getFileStreamPath(fileName));
like image 136
Bob Snyder Avatar answered Oct 12 '22 09:10

Bob Snyder


Figured it out I think:

final File file = new File(getFilesDir(), "webImage");
Uri weburi = Uri.fromFile(file);
like image 38
Ethan Allen Avatar answered Oct 12 '22 11:10

Ethan Allen