Skip to content

Commit ad28a0e

Browse files
darron1217infil00p
authored andcommitted
Add Support for input[type=file] File Chooser
1 parent fa70a64 commit ad28a0e

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

src/android/InAppBrowser.java

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public String openExternal(String url) {
409409
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
410410
this.cordova.getActivity().startActivity(intent);
411411
return "";
412-
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
412+
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
413413
} catch (java.lang.RuntimeException e) {
414414
LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
415415
return e.toString();
@@ -571,7 +571,7 @@ public String showWebPage(final String url, HashMap<String, Boolean> features) {
571571
}
572572
Boolean wideViewPort = features.get(USER_WIDE_VIEW_PORT);
573573
if (wideViewPort != null ) {
574-
useWideViewPort = wideViewPort.booleanValue();
574+
useWideViewPort = wideViewPort.booleanValue();
575575
}
576576
}
577577

@@ -586,8 +586,8 @@ public String showWebPage(final String url, HashMap<String, Boolean> features) {
586586
*/
587587
private int dpToPixels(int dipValue) {
588588
int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
589-
(float) dipValue,
590-
cordova.getActivity().getResources().getDisplayMetrics()
589+
(float) dipValue,
590+
cordova.getActivity().getResources().getDisplayMetrics()
591591
);
592592

593593
return value;
@@ -695,8 +695,8 @@ public void onClick(View v) {
695695
public boolean onKey(View v, int keyCode, KeyEvent event) {
696696
// If the event is a key-down event on the "enter" button
697697
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
698-
navigate(edittext.getText().toString());
699-
return true;
698+
navigate(edittext.getText().toString());
699+
return true;
700700
}
701701
return false;
702702
}
@@ -892,6 +892,42 @@ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Statu
892892
}
893893
}
894894

895+
/**
896+
* Receive File Data from File Chooser
897+
*
898+
* @param requestCode the requested code from chromeclient
899+
* @param resultCode the result code returned from android system
900+
* @param intent the data from android file chooser
901+
*/
902+
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
903+
// For Android >= 5.0
904+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
905+
Log.i("mytag", "onActivityResult (For Android >= 5.0)");
906+
// If RequestCode or Callback is Invalid
907+
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
908+
super.onActivityResult(requestCode, resultCode, intent);
909+
return;
910+
}
911+
mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
912+
mUploadCallbackLollipop = null;
913+
}
914+
// For Android < 5.0
915+
else {
916+
Log.i("mytag", "onActivityResult (For Android < 5.0)");
917+
// If RequestCode or Callback is Invalid
918+
if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
919+
super.onActivityResult(requestCode, resultCode, intent);
920+
return;
921+
}
922+
923+
if (null == mUploadCallback) return;
924+
Uri result = intent == null || resultCode != cordova.getActivity().RESULT_OK ? null : intent.getData();
925+
926+
mUploadCallback.onReceiveValue(result);
927+
mUploadCallback = null;
928+
}
929+
}
930+
895931
/**
896932
* The webview client receives notifications about appView
897933
*/
@@ -999,7 +1035,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
9991035
// Update the UI if we haven't already
10001036
if (!newloc.equals(edittext.getText().toString())) {
10011037
edittext.setText(newloc);
1002-
}
1038+
}
10031039

10041040
try {
10051041
JSONObject obj = new JSONObject();
@@ -1087,35 +1123,5 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
10871123
// By default handle 401 like we'd normally do!
10881124
super.onReceivedHttpAuthRequest(view, handler, host, realm);
10891125
}
1090-
1091-
@Override
1092-
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
1093-
// For Android >= 5.0
1094-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
1095-
Log.i("mytag", "onActivityResult (For Android >= 5.0)");
1096-
// If RequestCode or Callback is Invalid
1097-
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
1098-
super.onActivityResult(requestCode, resultCode, intent);
1099-
return;
1100-
}
1101-
mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
1102-
mUploadCallbackLollipop = null;
1103-
}
1104-
// For Android < 5.0
1105-
else {
1106-
Log.i("mytag", "onActivityResult (For Android < 5.0)");
1107-
// If RequestCode or Callback is Invalid
1108-
if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
1109-
super.onActivityResult(requestCode, resultCode, intent);
1110-
return;
1111-
}
1112-
1113-
if (null == mUploadCallback) return;
1114-
Uri result = intent == null || resultCode != cordova.getActivity().RESULT_OK ? null : intent.getData();
1115-
1116-
mUploadCallback.onReceiveValue(result);
1117-
mUploadCallback = null;
1118-
}
1119-
}
11201126
}
1121-
}
1127+
}

0 commit comments

Comments
 (0)