12

What I wanna do:

I wanna get the path as a String of a file, which I choose via an Android File Manager.

What I have:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Open with ..."), FILE_SELECT_CODE);

This code, works nearly fine for me, but there is one problem. I can only select my file with the following apps:

enter image description here

My Question:

Does anyone have a working code for choosing any file via the Android File Manager?

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Pixel_95
  • 954
  • 2
  • 9
  • 21
  • "but there is one problem: I can only select my file with the following apps" -- why is that a problem? "Does anyone have a working code for choosing any file via the Android File Manager?" -- Android does not *have* a file manager. The closest thing is [the Storage Access Framework](http://developer.android.com/guide/topics/providers/document-provider.html), available on API Level 19+. – CommonsWare Sep 29 '15 at 22:10
  • 1
    Its a problem, 'cause I also wanna send .pdf or something like this, so I need to pic my file with a File Manager, not with the Gallery – Pixel_95 Sep 29 '15 at 22:14

2 Answers2

22

You can use this:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*"); 
startActivityForResult(intent, REQUEST_CODE);

For samsung devices to open file manager use this:

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);

For more reference checkout http://developer.android.com/guide/topics/providers/document-provider.html

phrogg
  • 888
  • 1
  • 13
  • 28
Aakash
  • 5,181
  • 5
  • 20
  • 37
2

So for my Samsung device this worked:

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, FILE_SELECT_CODE);
Pixel_95
  • 954
  • 2
  • 9
  • 21