1

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?

enter image description here

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()));
                    }
                }
            }
        }
    }
NewDroid
  • 35
  • 5
  • 1
    That code will not run on any Android 10 device unless you added legacyExternalStorage="true" to manifest file. – blackapps Jul 22 '20 at 07:18
  • Is that your listview? Or from one or other file manager app? – blackapps Jul 22 '20 at 07:20
  • Adding requestLegacyExternalStorage to my manifest works but it also causes my app to crash after recording. – NewDroid Jul 22 '20 at 11:59
  • Well look in the logcat to find the exception that you did not catch. Post relevant lines from logcat here. – blackapps Jul 22 '20 at 12:36
  • Thanks. The problem is that when I run this code on my local computer, in Android Studio's Emulator, on a Pixel running Android 10 I do not get the original problem nor do I get the crash after adding requestLegacyExternalStorage. I get the original problem and the crash while using Samsung Remote Lab while testing on Samsung phones running Android 10. I saw this in the log on Samsung Remote Lab: Accessing hidden method Lsun/misc/Unsafe – NewDroid Jul 22 '20 at 12:48
  • I have no idea what would be 'using Samsungs Remote Lab'. – blackapps Jul 22 '20 at 13:23
  • This is Samsung Remote Test Lab. https://developer.samsung.com/remote-test-lab – NewDroid Jul 22 '20 at 14:46
  • Great. But thats an emulator on the web. Do you trust it? I would try a real device. – blackapps Jul 22 '20 at 15:08
  • OK, I'll try a real device. – NewDroid Jul 22 '20 at 15:30

1 Answers1

1

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

<application
android:requestLegacyExternalStorage="true"
</application>
Felix
  • 284
  • 2
  • 12
  • Thanks for your suggestion. Adding requestLegacyExternalStorage to my manifest works but it also causes my app to crash after recording. – NewDroid Jul 22 '20 at 11:59
  • Thanks. The problem is that when I run this code on my local computer, in Android Studio's Emulator, on a Pixel running Android 10 I do not get the original problem nor do I get the crash after adding requestLegacyExternalStorage. I get the original problem and the crash while using Samsung Remote Lab while testing on Samsung phones running Android 10. I saw this in the log on Samsung Remote Lab: Accessing hidden method Lsun/misc/Unsafe – NewDroid Jul 22 '20 at 12:48
  • do you use android studio? are there more information about the error in the log files? have you tested it on a real device? maybe there are problems with the emulator? – Felix Jul 22 '20 at 13:01
  • Yes, we have tested on real Samsung devices running Android 10 and we get the original issue. We have not tested on a real device after adding android:requestLegacyExternalStorage="true" yet. Yes, I use Android Studio and neither the original issue nor the crash is present when using the Emulator with Pixel runnig Android 10. – NewDroid Jul 22 '20 at 13:28
  • test it again on the real device to find out if it is samsung device or samsung lab. if it is samsung device you will get the error code. i can't help you with the information so far. i only test my camera apps on real devices, because in the emulator some things work differently. if you know more i will help you. – Felix Jul 22 '20 at 13:41
  • OK, I'll see if I test again on a real device. – NewDroid Jul 22 '20 at 13:56