File Not Found... Selecting A Video From Gallery
Solution 1:
"URI" or "absolute paths" to a video file that I selected from gallery
Those are Uri
values. They are not filesystem paths, nor can you get filesystem paths for them.
The file is NOT found.
That is because they are not files. content://com.android.providers.media.documents/document/video%3A5312
has a scheme of content
, not file
.
Similarly, https://stackoverflow.com/questions/41900707/file-not-found-selecting-a-video-from-gallery
is not a file, as that Uri
has a scheme of https
.
How do I open it with File()?
You don't, any more than you open https://stackoverflow.com/questions/41900707/file-not-found-selecting-a-video-from-gallery
using File
.
Instead, you use ContentResolver
and openInputStream()
to get an InputStream
on the content identified by the Uri
, just as you might use OkHttp or HttpUrlConnection
to get an InputStream
on an https
Uri
.
Solution 2:
Ok. Thank you.
Here's what I managed....
String[] perms = {"android.permission. WRITE_EXTERNAL_STORAGE"};
intpermsRequestCode=200;
requestPermissions(perms, permsRequestCode);
publicvoidconvertFile(Uri urx)throws IOException {
ContentResolvertest= getContentResolver();
InputStreaminitialStream= test.openInputStream(urx);
byte[] buffer = newbyte[initialStream.available()];
initialStream.read(buffer);
Filexpath= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
FiletargetFile=newFile(xpath, "/test.mp4");
OutputStreamoutStream=newFileOutputStream(targetFile);
outStream.write(buffer);
uploadFile(targetFile.getPath());
}
@OverridepublicvoidonRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults){
switch(permsRequestCode){
case200:
booleanwriteAccepted= grantResults[0]== PackageManager.PERMISSION_GRANTED;
break;
}
}
I get an EACES error upon trying to write my .mp4 file. Is there a way to "write it to memory" ? Or maybe you can resolve this issue.
Post a Comment for "File Not Found... Selecting A Video From Gallery"