0

When opening a file picker with the following method:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooserIntent = Intent.createChooser(intent, "Open file");
startActivityForResult(chooserIntent, REQUEST_CODE_FILE_PICKER);

unless a default has been set, this will present the user with a choice of file pickers to use. How do you make your own, internal, file chooser available as one of the choices of file pickers presented to the user (such as the Material File Picker)?

drmrbrewer
  • 11,491
  • 21
  • 85
  • 181
  • http://developer.android.com/reference/android/content/Intent.html#EXTRA_INITIAL_INTENTS – CommonsWare Apr 24 '16 at 13:06
  • Thanks, I'll have a look at that. Are you able to provide any guidance in relation to a related topic here: http://stackoverflow.com/q/36821133/4070848 ? – drmrbrewer Apr 24 '16 at 14:10

1 Answers1

0

Thanks to @CommonsWare's comment, here is the extra bit of code needed to add the internal file picker to the list of choices presented to the user:

// this bit is as before...
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooserIntent = Intent.createChooser(intent, "Open file");

// new bit... create Intent for the internal file picker...
Intent materialFilePickerIntent = new Intent(this, FilePickerActivity.class);
materialFilePickerIntent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.txt$"));

// and add the picker to the list...
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { materialFilePickerIntent });

// finally, startActivityForResult() as before...
startActivityForResult(chooserIntent, REQUEST_CODE_FILE_PICKER);
drmrbrewer
  • 11,491
  • 21
  • 85
  • 181