diff --git a/android/src/main/java/com/filepicker/FilePickerModule.java b/android/src/main/java/com/filepicker/FilePickerModule.java index 1502e4b..dc52e6e 100644 --- a/android/src/main/java/com/filepicker/FilePickerModule.java +++ b/android/src/main/java/com/filepicker/FilePickerModule.java @@ -55,6 +55,7 @@ public String getName() { @ReactMethod public void showFilePicker(final ReadableMap options, final Callback callback) { Activity currentActivity = getCurrentActivity(); + String mimeType = options.hasKey("mimeType") ? options.getString("mimeType") : "*/*"; response = Arguments.createMap(); if (currentActivity == null) { @@ -62,13 +63,12 @@ public void showFilePicker(final ReadableMap options, final Callback callback) { callback.invoke(response); return; } - - launchFileChooser(callback); + launchFileChooser(callback, mimeType); } // NOTE: Currently not reentrant / doesn't support concurrent requests @ReactMethod - public void launchFileChooser(final Callback callback) { + public void launchFileChooser(final Callback callback, final String mimeType) { int requestCode; Intent libraryIntent; response = Arguments.createMap(); @@ -82,7 +82,7 @@ public void launchFileChooser(final Callback callback) { requestCode = REQUEST_LAUNCH_FILE_CHOOSER; libraryIntent = new Intent(Intent.ACTION_GET_CONTENT); - libraryIntent.setType("*/*"); + libraryIntent.setType(mimeType); libraryIntent.addCategory(Intent.CATEGORY_OPENABLE); if (libraryIntent.resolveActivity(mReactContext.getPackageManager()) == null) { @@ -249,4 +249,4 @@ public static String getDataColumn(Context context, Uri uri, String selection, return null; } -} \ No newline at end of file +}