0

I tried it but I found null array exception I want to show all files and folders like file manager, if we click on any folder then all files have to show there of directory

package com.example.hostpot;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ArrayAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends ListActivity {
    List<String> listFile = new ArrayList<String>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        File root = new File(Environment.getExternalStorageDirectory().getName());
        ListDir(root);
    }
    void ListDir(File f){
        File[] flist = f.listFiles();
        listFile.clear();
        for (File file : flist){
            listFile.add(file.getPath());
        }
        ArrayAdapter<String> dir = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listFile);
        setListAdapter(dir);
    }
}
  • Does this answer your question? [How to list files in an android directory?](https://stackoverflow.com/questions/8646984/how-to-list-files-in-an-android-directory) – Shalu T D Jun 27 '20 at 13:38
  • You do not appear to be requesting permissions to have access to external storage, which is required on Android 6.0+. Also note that by default you do not have read access to external storage, even with permission, on Android 10. – CommonsWare Jun 27 '20 at 13:42

0 Answers0