I found a way to list all the directory in internal storage. please try this, it work's fine for me as i am using only internal storage in my phone.
MainActivity.java
package com.sumesh.filendirectory;
import android.app.ListActivity;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class FileNDirectoryActivity extends ListActivity {
private List<String> fileList=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File root=new File(Environment.getExternalStorageDirectory().getAbsolutePath());
ListDir(root);
}
void ListDir(File f){
File[] files=f.listFiles();
fileList.clear();
for (File file: files){
fileList.add(file.getPath());
}
ArrayAdapter<String> directoryList=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,fileList);
setListAdapter(directoryList);
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sumesh.filendirectory">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FileNDirectoryActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
hope it helps.
if you are using android version 6 or above, once you install the app it will crash for sure because of storage run-time permission now how to resolve? add run-time permission code for storage and if you are lazy follow this one.
- goto ==> installed app ==> app info screen
- on permission list item give storage permission then it will run smoothly.

Other ways to do so:
MainActivity.java
public class MainActivity extends AppCompatActivity {
ListView lview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lview = (ListView) findViewById(R.id.lview1);
String path=Environment.getExternalStorageDirectory().getAbsolutePath();
File f = new File(path);//converted string object to file
String[] values = f.list();//getting the list of files in string array
//now presenting the data into screen
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_dropdown_item, values);
lview.setAdapter(adapter);//setting the adapter
}
}
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lview1">
</ListView>
</LinearLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sumesh.listview">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
