我在运行Android 10的三星手机上使用以下代码遇到问题。该代码应获取录制的视频并将其显示在应用程序的“我的视频”屏幕上。该代码在运行Android 10的Samsung手机上不起作用。以下屏幕截图显示了该代码在非运行Android 10的Samsung手机上显示的内容。在运行Android 10的Samsung手机上,列表视图为空白。有任何想法吗?
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()));
}
}
}
}
}
我认为这与以下事实有关:从android 10开始,您无法将文件保存在自己的应用程序文件夹之外。有一些解决方法:
目前,我在第一种选择上做得很好,可以将requestLegacyExternalStorage添加到清单中
<application
android:requestLegacyExternalStorage="true"
</application>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句