We're able to get a Uri from Camera, Gallery, Video Camera Intent. We will obtain a Uri from the intent then you can use it to get a temp File.
Created
January 26, 2017 09:47
-
-
Save pokk/3de2774982e9abecb6d9393e6602d382 to your computer and use it in GitHub Desktop.
from InputStream to File.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We can get input stream from uri. | |
InputStream inputStream = getContentResolver().openInputStream(uri); | |
public static File stream2File(InputStream in) throws IOException { | |
File tmpFile = File.createTempFile("tmp", ".jpg"); | |
tmpFile.deleteOnExit(); | |
// compile "org.apache.directory.studio:org.apache.commons.io:2.4" | |
IOUtils.copy(inputStream, new FileOutputStream(tmpFile)); | |
// You got a [tmpFile] from [inputStream]. | |
return tmpFilel; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment