Page 1 of 1

Select directory only with AndExplorer Intent

Posted: Tue May 19, 2009 6:49 pm
by support
Starting in 1.0 BETA3, AndExplorer provides an Intent to select a directory. See below for a sample code you can integrate in your application. We assume that AndExplorer is installed.

Code: Select all

Intent intent = new Intent();
// Initial directory to browse.
Uri startDir = Uri.fromFile(new File("/sdcard"));
// Directory only !
intent.setDataAndType(startDir, "");
// Title to display.
intent.putExtra("explorer_title", "Select a directory");
// Optional colors.
intent.putExtra("browser_title_background_color", "44AA0000");
intent.putExtra("browser_title_foreground_color", "FFFFFFFF");
intent.putExtra("browser_list_background_color", "66000000");
// Optional font scale (default is 100%)
intent.putExtra("browser_list_fontscale", "120%");
// Optional 0=simple list, 1 = list with filename and size, 2 = list with filename, size and date.
intent.putExtra("browser_list_layout", "0");
startActivityForResult(intent, PICK_REQUEST_CODE);
AndExplorer will be launched with startActivityForResult and once end-user has selected a directory your application is notified:

Code: Select all

protected void onActivityResult(int requestCode, int resultCode, Intent intent) 
   if (requestCode == PICK_REQUEST_CODE) 
	if (resultCode == RESULT_OK) 
		Uri uri = intent.getData();
		String type = intent.getType();
		LogHelper.i(TAG,"Pick completed: "+ uri + " "+type);
		if (uri != null)
			String path = uri.toString();
			if (path.toLowerCase().startsWith("file://"))
				// Selected directory path is below
				path = (new File(URI.create(path))).getAbsolutePath();

	else LogHelper.i(TAG,"Back from pick with cancel status");
Here is the UI displayed with this Intent call:
selectdir.png (20.63 KiB) Viewed 3428 times
End-user has to long click to select directory. Simple click just open the directory to browse.