Select any file via Intent on Android

I would like to start makechooser for applications that can return any file

I am currently using (which I copied from the Android email source code to attach the file)

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); Intent i = Intent.createChooser(intent, "File"); startActivityForResult(i, CHOOSE_FILE_REQUESTCODE); 

But it only shows “Gallery” and “Music Player” on my Galaxy S2. There is a file explorer on this device, and I would like it to appear in the list. I would also like the camera application to appear in the list so that the user can take a picture and send it through my application. If I install Astro file manager, it will also respond to this intention. My customers own Galaxy SII, and I don’t want to force them to install Astro a file manager, given that they already have a basic but sufficient file manager.

Any idea on how I can achieve this? I am sure that I have already seen that a file appears in the file manager in such a menu, but I can’t remember which application.

+77
android file android-intent intentfilter
Jan 20 '12 at 17:38
source share
5 answers

Not for the camera, but for other files.

I have ES File Explorer installed on my device and it just works in my case ..

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("file/*"); startActivityForResult(intent, PICKFILE_REQUEST_CODE); 
+69
Jan 20 '12 at 18:21
source share

Samsung Explorer requires not only a custom action ( com.sec.android.app.myfiles.PICK_DATA ), but also part of the category (Intent. CATEGORY_DEFAULT ) and mime-type, which should be passed as optional.

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

You can also use this action to open several files: com.sec.android.app.myfiles.PICK_DATA_MULTIPLE Anyway, here is my solution that works on Samsung and other devices:

 public void openFile(String mimeType) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType); intent.addCategory(Intent.CATEGORY_OPENABLE); // special intent for Samsung file manager Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); // if you want any file type, you can skip next line sIntent.putExtra("CONTENT_TYPE", mimeType); sIntent.addCategory(Intent.CATEGORY_DEFAULT); Intent chooserIntent; if (getPackageManager().resolveActivity(sIntent, 0) != null){ // it is device with Samsung file manager chooserIntent = Intent.createChooser(sIntent, "Open file"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent}); } else { chooserIntent = Intent.createChooser(intent, "Open file"); } try { startActivityForResult(chooserIntent, CHOOSE_FILE_REQUESTCODE); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT).show(); } } 

This solution works well for me, and may be useful for someone else.

+41
Jul 30 '13 at 14:30
source share

this work is for me on a galaxy note his show contacts, file managers installed on the device, gallery, music player

 private void openFile(Int CODE) { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("*/*"); startActivityForResult(intent, CODE); } 

enter the path in the onActivityResult activity.

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { String Fpath = data.getDataString(); // do somthing... super.onActivityResult(requestCode, resultCode, data); } 
+31
Jun 25 2018-12-12T00:
source share

It turns out Samsung File Explorer uses a custom action. That's why I could see the Samsung file browser when searching for a file from Samsung applications, but not from mine.

Action: "com.sec.android.app.myfiles.PICK_DATA"

I created a custom Activity Picker that displays actions filtering both intentions.

+1
Jan 23 '12 at 10:41
source share

If you want to know this, there is an open source library called aFileDialog , which is small and easy to use, which provides a file collector.

The difference with other Android file libraries is that aFileDialog gives you the ability to open a selection file as a dialog and as an action.

It also allows you to select folders, create files, filter files using regular expressions, and display confirmation dialogs.

-one
Apr 03 '14 at 9:33
source share



All Articles