スマートフォンのストレージの一覧を表示して、フォルダならその中を一覧表示、ファイルならチェックボックスで選択するサンプルコードです。

サンプル

activity_main.xml

					
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	tools:context=".MainActivity">

	<ListView android:id="@+id/listview"
			android:layout_width="fill_parent"
			android:layout_height="fill_parent"
			android:choiceMode="multipleChoice"/>
</LinearLayout>

MainActivity.java

					
public class MainActivity extends AppCompatActivity {
	File externalStorageDir;    // 内部ストレージベースフォルダー
	String externalStorageGoUp; // 上位フォルダへ移動の印
	String externalStorageFolder;   // 選択フォルダー/ファイル
	ListView listView;              // ListView
	ArrayList externalStorageInfo; // ファイル種類情報
	File mapFile;   // 選択ファイル

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		externalStorageGoUp = "../";    // 上位フォルダへ移動の印
		externalStorageDir = Environment.getExternalStorageDirectory(); // 内部ストレージベースフォルダー

		// 内部ストレージフォルダー情報取得
		String SDstatus = Environment.getExternalStorageState();
		// 内部ストレージが確認できない場合
		if (SDstatus.equals(Environment.MEDIA_MOUNTED) == false &&
				SDstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY) == false) {
			new AlertDialog.Builder(this)
			.setTitle("警告")
			.setMessage("SDカードがセットされていません。")
			.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			})
			.show();
		}
		// ListViewを生成
		listView = this.findViewById(R.id.listview);
		listView.setItemsCanFocus(false);
		// 複数選択モードを指定する
		listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
				Map map = (Map) arg0.getItemAtPosition(arg2);
				mapFile = (File) map.get("file");

				externalStorageFolder = mapFile.getAbsolutePath();
				if (mapFile.isDirectory()) {
					updateList(mapFile);    // フォルダ内展開
				}
			}
		});
		updateList(externalStorageDir);
	}
	/*
		* フォルダ内をListViewへ展開
		*/
	public void updateList(File dir) {

		// 選択されたファイル名/フォルダ名をセット
		externalStorageFolder = dir.getAbsolutePath();

		// リスト情報生成
		SimpleAdapter adapter = new SimpleAdapter(this, getData(dir.listFiles(), dir.getParentFile()),
				android.R.layout.simple_list_item_multiple_choice, new String[]{"name"},
				new int[]{android.R.id.text1});

		listView.setAdapter(adapter);
	}
	@TargetApi(Build.VERSION_CODES.KITKAT)
	private List  getData(File[] files, File parent) {

		Map temp;
		List myData = new ArrayList();
		externalStorageInfo = new ArrayList();
		externalStorageInfo.clear();

		// 上位へ移動できるフォルダがある場合に設定
		if(parent != null && externalStorageDir.getParent().equals(parent.getAbsolutePath()) == false) {
			externalStorageDir = Environment.getExternalStorageDirectory();
			if (externalStorageDir.getParent().equals(parent.getAbsolutePath()) == false) {
				temp = new HashMap();
				externalStorageInfo.add(new ExternalStorageInfo(externalStorageGoUp, "a", parent));
				myData.add(temp);
			}

		} else {
			if (!Environment.getExternalStorageDirectory().getPath().equals(externalStorageFolder)) {
				temp = new HashMap();
				externalStorageInfo.add(new ExternalStorageInfo(externalStorageGoUp, "a", parent));
				myData.add(temp);
			}

		}
		// ファイル情報展開
		if (files != null) {
			for (File file : files) {
				temp = new HashMap();
				if (file.isDirectory()) {
					externalStorageInfo.add(new ExternalStorageInfo(file.getName() + "/", "d", file));
				} else {
					externalStorageInfo.add(new ExternalStorageInfo(file.getName(), "f", file));
				}
				myData.add(temp);
			}
		}
		// 並び替え
		new CollectionsSortSample().sortMyDto(externalStorageInfo);
		myData.clear();
		for (int i = 0; i < externalStorageInfo.size(); i++) {
			temp = new HashMap();
			temp.put("name", externalStorageInfo.get(i).getName());
			temp.put("file", externalStorageInfo.get(i).getFile());
			myData.add(temp);
		}

		return myData;

	}
	/*
		* ストレージ情報保存クラス
		*/
	public class ExternalStorageInfo {
		public String name;
		public String type;
		public File file;

		public ExternalStorageInfo(String s, String d, File f) {
			this.name = s;
			this.type = d;
			this.file = f;
		}
		public String getName() { return this.name; }
		public void setName(String nm) { this.name = nm; }
		public String getType() { return this.type; }
		public void setType(String tp) { this.type = tp; }
		public File getFile() { return this.file; }
		public void setFile(File fl) { this.file = fl; }
	}
	/**
		* Collections#Sort
		*/
	public class CollectionsSortSample {
		/**
			* MyDtoリストをdata1-data2-data3の昇順にソートする
			*
			* @param dtoList
			*/
		public void sortMyDto(List dtoList) {
			Collections.sort(dtoList, new Comparator() {
				public int compare(ExternalStorageInfo o1, ExternalStorageInfo o2) {
					int comp = compareString(o1.getType(), o2.getType());
					if (comp != 0) {
						return comp;
					}
					comp = compareString(o1.getName(), o2.getName());
					if (comp != 0) {
						return comp;
					}
					return 0;
				}

				private int compareString(String s1, String s2) {
					if (s1 == null && s2 == null) return 0;
					else if (s1 == null) return -1;
					else if (s2 == null) return 1;
					else return s1.compareTo(s2);
				}
			});
		}
	}
}					

AndroidManifest.xml

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

注意

作成したアプリをインストールした後、
権限でストレージをONにしてください。