在运行Android 10的三星手机上,下面的代码有问题。代码应该获取录制的视频,并将它们显示在应用程序的My视频屏幕上。该代码不适用于运行安卓10的三星手机。下面的屏幕截图显示了代码在手机上显示的内容,而不是运行安卓10的三星手机。在运行安卓10的三星手机上,列表视图为空白。有什么想法吗?

private void getLegalVideos() {
File legalDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), IMAGE_DIRECTORY_NAME);
String pattern = ".mp4";
//Get the listfile of that folder
final File[] listFile = legalDir.listFiles();
if (listFile != null) {
for (File file : listFile) {
if (!file.isDirectory()) {
if (file.getName().endsWith(pattern)) {
// Do what ever u want, add the path of the video to the list
Log.d(TAG, file.getAbsolutePath());
mLegalVideos.add(new VideoItem(file.getName(), file.getAbsolutePath()));
}
}
}
}
}发布于 2020-07-22 07:18:13
我认为这与这样一个事实有关:从android 10开始,你不能将文件保存在你自己的应用程序文件夹之外。有一些解决办法:
目前,我对第一个选项做得很好,将requestLegacyExternalStorage添加到您的清单中。
<application
android:requestLegacyExternalStorage="true"
</application>https://stackoverflow.com/questions/63028586
复制相似问题