We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I've tried several code snippets to get the file names of a specific directory, but all gave me a null. What would be the correct way? Thanks in advance.
import java.io.File;
import android.os.Environment;
// String path = Environment.getExternalStorageDirectory().toString()+"/Download";
String path = "/storage/emulated/legacy/Download";
File f = new File(path);
File[] files = f.listFiles();
printArray(files);
Answers
@noel===
snippet::
(dont forget to ask permissions for WRITE_EXTERNAL_STORAGE)
Thank you once more. I didn't think this would be necessary since I'm not writing anything. But that's it; all code above works now.
BTW Why giving the read permission (what would seem more obvious to me) gives the error
Manifest.permission.READ_EXTERNAL_STORAGE cannot be resolved