Skip to content

Commit 0534950

Browse files
committed
fix: handle empty uri array from file chooser result
1 parent a09b398 commit 0534950

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/android/app/src/main/java/io/literal/ui/fragment/AppWebView.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.json.JSONObject;
2828

2929
import java.io.File;
30+
import java.util.ArrayList;
3031
import java.util.UUID;
3132

3233
import io.literal.BuildConfig;
@@ -280,17 +281,22 @@ public boolean onShowFileChooser(android.webkit.WebView webView, ValueCallback<U
280281
fileActivityResultCallback.setFilePathCallback(new ValueCallback<Uri[]>() {
281282
@Override
282283
public void onReceiveValue(Uri[] value) {
283-
Uri[] absoluteUrls = new Uri[value.length];
284+
ArrayList<Uri> absoluteUrls = new ArrayList<>();
284285
for (int idx = 0; idx < value.length; idx++) {
285-
File file = value[idx] != null ? ContentResolverLib.toFile(
286-
getActivity(),
287-
StorageObject.getDirectory(getContext(), StorageObject.Type.SCREENSHOT),
288-
value[idx],
289-
UUID.randomUUID().toString()
290-
) : null;
291-
absoluteUrls[idx] = Uri.fromFile(file);
286+
if (value[idx] != null) {
287+
File file = ContentResolverLib.toFile(
288+
getActivity(),
289+
StorageObject.getDirectory(getContext(), StorageObject.Type.SCREENSHOT),
290+
value[idx],
291+
UUID.randomUUID().toString()
292+
);
293+
absoluteUrls.add(Uri.fromFile(file));
294+
}
295+
}
296+
297+
if (absoluteUrls.size() > 0) {
298+
filePathCallback.onReceiveValue(absoluteUrls.toArray(new Uri[0]));
292299
}
293-
filePathCallback.onReceiveValue(absoluteUrls);
294300
}
295301
});
296302
getFileContent.launch("image/*");

0 commit comments

Comments
 (0)