From d64904062925fbd3f7b885427ecbb764b4ce7d7c Mon Sep 17 00:00:00 2001 From: Luca Caprini Date: Mon, 29 May 2017 16:36:01 +0200 Subject: [PATCH] FIX showOpenWithDialog on Android --- .../cordova/plugins/fileopener2/FileOpener2.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java index f5c7cb3..c74b6ce 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -60,8 +60,11 @@ public class FileOpener2 extends CordovaPlugin { if (action.equals("open")) { String fileUrl = args.getString(0); String contentType = args.getString(1); - Boolean openWith = (args.length() > 2) && args.getBoolean(2); - this._open(fileUrl, contentType, openWith, callbackContext); + Boolean openWithDefault = true; + if(args.length() > 2){ + openWithDefault = args.getBoolean(2); + } + this._open(fileUrl, contentType, openWithDefault, callbackContext); } else if (action.equals("uninstall")) { this._uninstall(args.getString(0), callbackContext); @@ -87,7 +90,7 @@ public class FileOpener2 extends CordovaPlugin { return true; } - private void _open(String fileArg, String contentType, Boolean openWith, CallbackContext callbackContext) throws JSONException { + private void _open(String fileArg, String contentType, Boolean openWithDefault, CallbackContext callbackContext) throws JSONException { String fileName = ""; try { CordovaResourceApi resourceApi = webView.getResourceApi(); @@ -124,11 +127,11 @@ public class FileOpener2 extends CordovaPlugin { * @see * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin */ - if(openWith){ - cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in...")); + if(openWithDefault){ + cordova.getActivity().startActivity(intent); } else{ - cordova.getActivity().startActivity(intent); + cordova.getActivity().startActivity(Intent.createChooser(intent, "Open File in...")); } callbackContext.success();