Select file (or directory) with AndExplorer Intent

File Manager/Explorer for Android devices.

Select file (or directory) with AndExplorer Intent

Postby support » Tue May 19, 2009 7:02 pm

Starting in 1.0 BETA3, AndExplorer provides an Intent to select a file or 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();
Uri startDir = Uri.fromFile(new File("/sdcard"));
// Files and directories !
intent.setDataAndType(startDir, "");
// Title
intent.putExtra("explorer_title", "Select a file");
// Optional colors
intent.putExtra("browser_title_background_color", "440000AA");
intent.putExtra("browser_title_foreground_color", "FFFFFFFF");
intent.putExtra("browser_list_background_color", "00000066");
// Optional font scale
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", "2");
startActivityForResult(intent, PICK_REQUEST_CODE);

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 file/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:
selectfile.png (28.77 KiB) Viewed 2524 times

Simple click select the file.
Posts: 882
Joined: Sun Apr 20, 2008 4:40 pm

Return to AndExplorer

Sitemap | Privacy Statement | Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc.
in the U.S. and other countries. All other company and/or product names are the property of their respective owners.