FIX showOpenWithDialog on Android

This commit is contained in:
Luca Caprini 2017-05-29 16:36:01 +02:00 committed by GitHub
parent 6b34b93af4
commit d649040629

View File

@ -60,8 +60,11 @@ public class FileOpener2 extends CordovaPlugin {
if (action.equals("open")) { if (action.equals("open")) {
String fileUrl = args.getString(0); String fileUrl = args.getString(0);
String contentType = args.getString(1); String contentType = args.getString(1);
Boolean openWith = (args.length() > 2) && args.getBoolean(2); Boolean openWithDefault = true;
this._open(fileUrl, contentType, openWith, callbackContext); if(args.length() > 2){
openWithDefault = args.getBoolean(2);
}
this._open(fileUrl, contentType, openWithDefault, callbackContext);
} }
else if (action.equals("uninstall")) { else if (action.equals("uninstall")) {
this._uninstall(args.getString(0), callbackContext); this._uninstall(args.getString(0), callbackContext);
@ -87,7 +90,7 @@ public class FileOpener2 extends CordovaPlugin {
return true; 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 = ""; String fileName = "";
try { try {
CordovaResourceApi resourceApi = webView.getResourceApi(); CordovaResourceApi resourceApi = webView.getResourceApi();
@ -124,11 +127,11 @@ public class FileOpener2 extends CordovaPlugin {
* @see * @see
* http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin
*/ */
if(openWith){ if(openWithDefault){
cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in...")); cordova.getActivity().startActivity(intent);
} }
else{ else{
cordova.getActivity().startActivity(intent); cordova.getActivity().startActivity(Intent.createChooser(intent, "Open File in..."));
} }
callbackContext.success(); callbackContext.success();