Ethan Allen Ethan Allen - 1 year ago 106
Java Question

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);
// remember close file output
} catch (Exception e) {

Answer Source

Use getFileStreamPath() like this:

String fileName = "webImage";
Uri uri = Uri.fromFile(getFileStreamPath(fileName));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download