如何解决在“下载”文件夹中下载视频 Android Q
根据 Android Q 及以上版本的限制,我正在尝试下载文件夹下的下载文件夹中的视频文件。但它总是需要到 Android/data/
String videoFileName = "video_" + System.currentTimeMillis() + ".mp4";
ContentValues valuesvideos;
valuesvideos = new ContentValues();
valuesvideos.put(MediaStore.Video.Media.RELATIVE_PATH,"Movies/" + "Folder");
valuesvideos.put(MediaStore.Video.Media.TITLE,videoFileName);
valuesvideos.put(MediaStore.Video.Media.DISPLAY_NAME,videoFileName);
valuesvideos.put(MediaStore.Video.Media.MIME_TYPE,"video/mp4");
valuesvideos.put(MediaStore.Video.Media.DATE_ADDED,System.currentTimeMillis() / 1000);
valuesvideos.put(MediaStore.Video.Media.DATE_TAKEN,System.currentTimeMillis());
valuesvideos.put(MediaStore.Video.Media.IS_PENDING,1);
ContentResolver resolver = mContext.getContentResolver();
Uri collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
Uri uriSavedVideo = resolver.insert(collection,valuesvideos);
ParcelFileDescriptor pfd;
try {
pfd = mContext.getContentResolver().openFileDescriptor(uriSavedVideo,"w");
FileOutputStream out = new FileOutputStream(pfd.getFileDescriptor());
File storageDir = new File(mContext.getExternalFilesDir(Environment.DIRECTORY_MOVIES),"Folder");
File imageFile = new File(storageDir,"Myvideo");
FileInputStream in = new FileInputStream(imageFile);
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf,len);
}
out.close();
in.close();
pfd.close();
} catch (Exception e) {
e.printStackTrace();
}
valuesvideos.clear();
valuesvideos.put(MediaStore.Video.Media.IS_PENDING,0);
mContext.getContentResolver().update(uriSavedVideo,valuesvideos,null,null);
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。