Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ this software and associated documentation files (the "Software"), to deal in
package io.github.pwlin.cordova.plugins.fileopener2;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
Expand All @@ -36,6 +37,7 @@ this software and associated documentation files (the "Software"), to deal in
import android.net.Uri;
import android.os.Build;
import android.webkit.MimeTypeMap;
import android.os.Environment;

import io.github.pwlin.cordova.plugins.fileopener2.FileProvider;

Expand Down Expand Up @@ -93,14 +95,17 @@ else if (action.equals("appIsInstalled")) {

private void _open(String fileArg, String contentType, Boolean openWithDefault, CallbackContext callbackContext) throws JSONException {
String fileName = "";
List<String> fileUriSegments = new ArrayList<>();
try {
CordovaResourceApi resourceApi = webView.getResourceApi();
Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
fileName = fileUri.getPath();
fileUriSegments = Uri.parse(fileArg).getPathSegments();
if(!fileUriSegments.isEmpty()) {
int numSegments = fileUriSegments.size() - 1;
fileName = fileUriSegments.get(numSegments);
}
} catch (Exception e) {
fileName = fileArg;
}
File file = new File(fileName);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);
if (file.exists()) {
try {
if (contentType == null || contentType.trim().equals("")) {
Expand Down