1

I want to choose a file via an Android File Manager.

so, to open file intent code is

Intent intent = new Intent();
intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select File"), 1);

But I was unable to access file manager in samsung devices to resolve this problem i do

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

But this code in not working in other devices so what should i do to open file manager in all devices ?

Arun J
  • 687
  • 4
  • 14
  • 27
Brinda Rathod
  • 2,693
  • 1
  • 20
  • 32
  • 1
    "I want to choose a file via an Android File Manager" -- not all devices have a "file manager" app installed. "should i do to open file manager in all devices ?" -- use `ACTION_GET_CONTENT` (or `ACTION_OPEN_DOCUMENT` on Android 4.4+). Or, [use a file chooser library](https://android-arsenal.com/tag/35). Also, `file/*` is not a valid MIME type. – CommonsWare Mar 23 '18 at 13:06
  • not working in samsung devices by using ACTION_GET_CONTENT (or ACTION_OPEN_DOCUMENT @CommonsWare – Brinda Rathod Mar 23 '18 at 13:21
  • Please explain in detail what "not working" means. – CommonsWare Mar 23 '18 at 13:21
  • didnt get my files option @CommonsWare – Brinda Rathod Mar 23 '18 at 13:22
  • Please explain **in detail** what "didnt get my files option" means. – CommonsWare Mar 23 '18 at 13:23
  • only gallery and other option shows but i want to select from file manager @CommonsWare – Brinda Rathod Mar 23 '18 at 13:23
  • There may not be a file manager on that device. Many devices do not ship with a file manager. The standard `ACTION_OPEN_DOCUMENT` UI shows a few locations by default, and accessing "internal files" is available via the overflow menu. – CommonsWare Mar 23 '18 at 13:25
  • but using Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); intent.putExtra("CONTENT_TYPE", "*/*"); intent.addCategory(Intent.CATEGORY_DEFAULT); startActivityForResult(intent, 1); this code i got acees to file manager but problem is this is not working in other devices @CommonsWare – Brinda Rathod Mar 23 '18 at 13:27
  • Correct. That is an undocumented, unsupported `Intent` action that will be available on some Samung devices (see `com.sec` in the action string). While Samsung is a popular manufacturer, their devices are a small percentage of the ~2 billion devices (and ~10,000 device models). – CommonsWare Mar 23 '18 at 13:29
  • so please suggest me common solution so that would work on all devices @CommonsWare – Brinda Rathod Mar 23 '18 at 13:31
  • I did. Use `ACTION_GET_CONTENT` (or `ACTION_OPEN_DOCUMENT` on Android 4.4+). Or, use a [file chooser library](https://android-arsenal.com/tag/35). You cannot force device manufacturers to add a file manager to their devices. You cannot force device manufacturers to document and support a common `Intent` structure for accessing their file managers. You cannot force users to install file managers. So, either work with the standard `Intent` actions in Android, or use a library that ships with your app. – CommonsWare Mar 23 '18 at 13:33
  • okay , I got it Thank you sir @CommonsWare – Brinda Rathod Mar 24 '18 at 05:45
  • java.io.FileNotFoundException: /data/data/com.user.rathod/files/document/primary:DCIM/Camera/20170927_183338.jpg: open failed: ENOENT (No such file or directory) @CommonsWare – Brinda Rathod Mar 24 '18 at 09:27
  • caught this error thrown by samsung devices @CommonsWare – Brinda Rathod Mar 24 '18 at 09:33
  • /document/primary:DCIM/Camera/20170927_183338.jpg This is image path – Brinda Rathod Mar 24 '18 at 09:40
  • 1
    You do not get back a file. You get back a `Uri`. The use of a `Uri` is covered in [the documentation](https://developer.android.com/guide/topics/providers/document-provider.html#client), plus books and courses on Android app development. See also [this blog post](https://commonsware.com/blog/2016/05/03/storage-access-framework-faq.html) and [this blog post](https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html). If you have further concerns in this area, ask a fresh question with a [mcve]. – CommonsWare Mar 24 '18 at 11:04

1 Answers1

2
private void openFile(int  requestCODE) {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType("*/*");
    startActivityForResult(intent, requestCODE);
}
Thankgod Richard
  • 507
  • 6
  • 16