0

My app is using a custom type of file that can be saved onto the external memory and shared.

I want to use the file picker to pick one file and load it. Here is my code :

Uri uri = Uri.fromFile("path/to/folder");
Intent intent = new Intent(Intent.ACTION_PICK, uri);
try {
    startActivityForResult(Intent.createChooser(intent, "Select a file"), 123);
} catch (android.content.ActivityNotFoundException e) {
    Toast.makeText(this, "Error fileChooser",Toast.LENGTH_SHORT).show();
    Log.e("Dan", "onOptionsItemSelected: Error filechooser ActivityNotFoundException", e);
}

This code works absolutely perfectly on my genymotion emulator and my Nexus 4 on CyanogenMod and call the file manager to browse to the folder.

But when I try on my brand new LG G4, it doesn't work. The biggest problem is that I get no error message, just a file picker with the good title and a message "No app can perform this action".

How to check if a file picker is available? (to provide a simple alternative if needed)

sathish kumar
  • 141
  • 1
  • 13
Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92

1 Answers1

1

Try this:

PackageManager packageManager = getActivity().getPackageManager();
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
intent.setType("file/*");
List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                                PackageManager.GET_ACTIVITIES));

Then, check the size of the list, if it is 0, then there is no file explorer.

cylon
  • 735
  • 1
  • 11
  • 26
  • Nice shot, but not very efficient. I get 3 responses with that : com.android.documentsui/.DocumentsActivity, com.dropbox.android/.activity.DropboxGetFrom and com.estrongs.android.pop/.app.ESContentChooserActivity. Still I cannot choose a file with that... – Dan Chaltiel Dec 27 '15 at 18:09
  • Oh OK that works, so apparently ES explorer cannot handle ACTION_PICK, and neither can any android native app... Thanks ! – Dan Chaltiel Dec 27 '15 at 18:18