11

I am using the below code which opens up the Gallery, Music Player, Dropbox and Contacts, i want the My Files folder to get open programatically, please let me know if there are any specific intent parameters i need to pass to get the File Manager open.

if it is not possible through intent then please give me a snippet or an hint to open the My Files folder programatically.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "View Default File Manager");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE); 

Thanks.

rkdroid
  • 151
  • 1
  • 2
  • 9

6 Answers6

5

You can use this code to file the files.

int PICKFILE_RESULT_CODE=1;            
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                 
intent.setType("file/*");              
startActivityForResult(intent,PICKFILE_RESULT_CODE);

this will help you to browse the files from your storage.

Aj_31
  • 187
  • 2
  • 6
  • this code help me... but i want view only .pdf extension files in my file explore. How it is possible? – patel135 Jan 22 '16 at 06:25
  • it will help to open custom file only, there is table there to see http://indyvision.net/android-snippets/android-using-intents-open-files/ – Irshad Babar Mar 19 '19 at 03:01
2

Its best that you include a library in your project which handles this scenario.

This worked for me:

This library shows the list of third-party apps. It also has its own file browser for selecting files.

Android Boy
  • 4,335
  • 6
  • 30
  • 58
varun
  • 465
  • 6
  • 23
1

Bad thing is, most Android distributions may or may not ship with a file manager, and even so, may be not with the one which handles CHOOSE_FILE_REQUESTCODE.

So, you are left to create your own file picker activity. Luckily there are many ready made ones available:

http://code.google.com/p/android-filechooser/

https://developers.inkfilepicker.com/docs/android/

S.D.
  • 29,290
  • 3
  • 79
  • 130
  • 1
    CHOOSE_FILE_REQUESTCODE is programmer defined, it is not an Android defined constant, right? – Radu Nov 07 '13 at 12:45
  • @Radu All System defined actions are defined as `ACTION_` constants in `Intent` class. `CHOOSE_FILE_REQUESTCODE` is not there. – S.D. Nov 07 '13 at 13:25
1

If you want to open samsung My Files application try this below code.

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");              
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE); 
  • What if it is not a Samsung? Like kinda of China phone? – NoWar May 03 '18 at 02:16
  • 2
    @AcademyofProgrammer The best bet would to make "chainable" intents, requesting the PackageManager if the Intent is resolvable. E.G: `if(intent.resolveActivity(getPackageManager())==null){intent=nextIntent;...}` – Bonatti Apr 18 '19 at 18:44
1

You have to specifically mention the package name of the explorer application. Please find the example below to open a specific folder in ES Explorer.

 public void openfolderInexplorer(String path){
  Intent intent = this.getPackageManager().getLaunchIntentForPackage("com.estrongs.android.pop");
 if (intent != null) {
           // If the application is avilable
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Uri uri = Uri.parse(path);
            intent.setDataAndType(uri, "resource/folder");
            this.startActivity(intent);
        } else {
            // Play store to install app
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id=" + 
            "com.estrongs.android.pop"));
            this.startActivity(intent);
        }
Rakshi
  • 6,796
  • 3
  • 25
  • 46
-1

try this below code. if any file manager available , then it will pop up in a form of menu to choose appropriate for the user.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE); 
AAnkit
  • 27,299
  • 12
  • 60
  • 71
  • How we can use it to open specific file only? I mean If I want to open the file of ".dco" extension, how it would be? – Irshad Babar Mar 19 '19 at 02:46
  • I found this link,it will help to open custom file only, there is table there to see http://indyvision.net/android-snippets/android-using-intents-open-files/ – Irshad Babar Mar 19 '19 at 03:02
  • CHOOSE_FILE_REQUESTCODE: you must define this yourself for your own reasons. It does not do that the question asks for. – Mick Apr 07 '23 at 15:12