英文:
Recorded video does not display on Samsung Phones Running Android 10
问题
我在三星手机上运行Android 10的以下代码中遇到了问题。该代码应该获取录制的视频并在应用的“我的视频”屏幕上显示它们。该代码在运行Android 10的三星手机上不起作用。下面的截图显示了代码在非三星手机上运行Android 10时的显示情况。在运行Android 10的三星手机上,列表视图是空白的。有什么想法?
private void getLegalVideos() {
File legalDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), IMAGE_DIRECTORY_NAME);
String pattern = ".mp4";
//获取该文件夹的文件列表
final File[] listFile = legalDir.listFiles();
if (listFile != null) {
for (File file : listFile) {
if (!file.isDirectory()) {
if (file.getName().endsWith(pattern)) {
// 做您想要的操作,将视频的路径添加到列表中
Log.d(TAG, file.getAbsolutePath());
mLegalVideos.add(new VideoItem(file.getName(), file.getAbsolutePath()));
}
}
}
}
}
英文:
I'm having a problem with the below code on Samsung phones running Android 10. The code should get the recorded videos and display them on the My Videos screen of the app. The code does not work on Samsungs phones running Android 10. The screenshot below shows what the code displays on phones that are not Samsung running Android 10. On Samsung phones running Android 10 the list view is blank. Any ideas?
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()));
}
}
}
}
}
答案1
得分: 1
我认为这与从Android 10开始,您无法将文件保存在自己的应用程序文件夹之外有关。有一些解决方法:
目前,我使用第一种选项表现得很好,即将requestLegacyExternalStorage
添加到您的清单文件中:
<application
android:requestLegacyExternalStorage="true"
</application>
英文:
I think it has to do with the fact that from android 10 on you can't save files outside your own app folder. There are a few workaround:
Currently I am doing well with the first option, to add requestLegacyExternalStorage to your manifest
<application
android:requestLegacyExternalStorage="true"
</application>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论