N
N
newdancer2016-08-18 20:35:51
Android
newdancer, 2016-08-18 20:35:51

The list of files on the memory card is not returned?

The list of files on the memory card is not returned?
I wrote in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I get a link:
String path = Environment.getExternalStorageDirectory().getAbsolutePath();

trying to get a list of memory card files
File f = new File(path);
    if(f.listFiles()!=null)
    {
      File[] files = f.listFiles();
      Arrays.sort(files);
      for ( File aFile : files ){
        if ( aFile.isDirectory() ) {
          if(dir_opened(aFile.getPath())){
            FileDir.add(aFile.getName());
          }
        }
      }
    }

but File f is null. I check on a real device. What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Gapchenko, 2016-08-18
@newdancer

You are probably running on Android 6. Permissions from this version must be requested at runtime. Here is an article for you to study.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question