Android Browser Dialog with Root Support

  • Posted on: 19 April 2014
  • By: siteadm

I was in the middle of coding some application for android and I needed a File/Folder browsing dialog. But I also needed access to /data and other sensitive folders. So I started searching internet, but I didn't find anything useful. Anyway, I decided to write my own. For initial code, I used sample project from here

I started expanding it, made some changes to it, added images for files and folders, added root access features, added known filetype icons, etc.

Anyway, full project is here

Even thought I've included sample project, I'll explain shortly how you can implement it in your own projects:

1) Add DirectoryPick project as a reference to your own project. (Right click on Project -> Properties -> Android -> Scroll down to Library part -> Click Add -> Choose DirectoryPick and press OK)

2) Add custom permissions DirectoryPick will need to your AndroidManifest.xml:





3) Add activity for DirectoryPick dialog:

 

4) Add code for starting the dialog:

Intent intent = new Intent(this, DirectoryPicker.class); 
if (ROOTACCESS) 
intent.putExtra(DirectoryPicker.USE_ROOT, true); 
else 
intent.putExtra(DirectoryPicker.USE_ROOT, false); 
if (DIRSONLY) 
intent.putExtra(DirectoryPicker.ONLY_DIRS, false); 
else 
intent.putExtra(DirectoryPicker.ONLY_DIRS, true);
intent.putExtra(DirectoryPicker.START_DIR, "/"); 
startActivityForResult(intent, DirectoryPicker.PICK_DIRECTORY); 

5) Add code for retrieving results:

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == DirectoryPicker.PICK_DIRECTORY && resultCode == RESULT_OK)
{
Bundle extras = data.getExtras();
String path = (String) extras.get(DirectoryPicker.CHOSEN_DIRECTORY); 
}
if(requestCode == DirectoryPicker.PICK_DIRECTORY && resultCode == RESULT_CANCELED)
{ // User cancelled dialog, nothing selected. 
}
} 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.