录制的视频在运行Android 10的三星手机上不显示。

huangapple go评论86阅读模式
英文:

Recorded video does not display on Samsung Phones Running Android 10

问题

我在三星手机上运行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?

录制的视频在运行Android 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()));
                    }
                }
            }
        }
    }

答案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:

click

Currently I am doing well with the first option, to add requestLegacyExternalStorage to your manifest

&lt;application
android:requestLegacyExternalStorage=&quot;true&quot;
&lt;/application&gt;

huangapple
  • 本文由 发表于 2020年7月22日 15:00:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63028586.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定