You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2017/01/09 17:47:36 UTC
[6/8] cordova-plugin-inappbrowser git commit: Add Support for
input[type=file] File Chooser
Add Support for input[type=file] File Chooser
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/fa70a64a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/fa70a64a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/fa70a64a
Branch: refs/heads/master
Commit: fa70a64af9494cd6d2ae840f5cca285ca26fecf0
Parents: f32917d
Author: \ubc15\uad00\uc601 <ja...@naver.com>
Authored: Tue Jan 3 14:09:17 2017 +0900
Committer: Joe Bowser <bo...@apache.org>
Committed: Mon Jan 9 09:27:53 2017 -0800
----------------------------------------------------------------------
src/android/InAppBrowser.java | 93 +++++++++++++++++++++++++++++++++++++-
1 file changed, 92 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/fa70a64a/src/android/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 24a8efa..b7a463c 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -68,6 +68,10 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.StringTokenizer;
+import android.util.Log;
+import android.webkit.ValueCallback;
+import android.webkit.WebChromeClient;
+
@SuppressLint("SetJavaScriptEnabled")
public class InAppBrowser extends CordovaPlugin {
@@ -104,6 +108,11 @@ public class InAppBrowser extends CordovaPlugin {
private boolean shouldPauseInAppBrowser = false;
private boolean useWideViewPort = true;
+ private ValueCallback<Uri> mUploadCallback;
+ private ValueCallback<Uri[]> mUploadCallbackLollipop;
+ private final static int FILECHOOSER_REQUESTCODE = 1;
+ private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2;
+
/**
* Executes the request and returns PluginResult.
*
@@ -722,7 +731,59 @@ public class InAppBrowser extends CordovaPlugin {
inAppWebView = new WebView(cordova.getActivity());
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
inAppWebView.setId(Integer.valueOf(6));
- inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
+
+ // File Chooser Implemented ChromeClient
+ inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) {
+ // For Android 5.0+
+ public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
+ {
+ Log.d(LOG_TAG, "File Chooser 5.0+");
+ // If callback exists, finish it.
+ if(mUploadCallbackLollipop != null) {
+ mUploadCallbackLollipop.onReceiveValue(null);
+ }
+ mUploadCallbackLollipop = filePathCallback;
+
+ // Create File Chooser Intent
+ Intent content = new Intent(Intent.ACTION_GET_CONTENT);
+ content.addCategory(Intent.CATEGORY_OPENABLE);
+ content.setType("*/*");
+
+ // [important] Register ActvityResultCallback on Cordova
+ cordova.setActivityResultCallback(InAppBrowser.this);
+ cordova.getActivity().startActivityForResult(content, FILECHOOSER_REQUESTCODE_LOLLIPOP);
+ return true;
+ }
+
+ // For Android 4.1+
+ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
+ {
+ Log.d(LOG_TAG, "File Chooser 4.1+");
+ // Call file chooser for Android 3.0+
+ openFileChooser(uploadMsg, acceptType);
+ }
+
+ // For Android 3.0+
+ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
+ {
+ Log.d(LOG_TAG, "File Chooser 3.0+");
+ mUploadCallback = uploadMsg;
+ Intent i = new Intent(Intent.ACTION_GET_CONTENT);
+ i.addCategory(Intent.CATEGORY_OPENABLE);
+
+ cordova.setActivityResultCallback(InAppBrowser.this);
+ cordova.getActivity().startActivityForResult( Intent.createChooser(i, "File Chooser"), FILECHOOSER_REQUESTCODE);
+ }
+
+ // For Android < 3.0
+ public void openFileChooser(ValueCallback<Uri> uploadMsg) {
+ Log.d(LOG_TAG, "File Chooser 3.0 <");
+ // Call file chooser for Android 3.0+
+ openFileChooser(uploadMsg, "");
+ }
+
+ });
+
WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
inAppWebView.setWebViewClient(client);
WebSettings settings = inAppWebView.getSettings();
@@ -1026,5 +1087,35 @@ public class InAppBrowser extends CordovaPlugin {
// By default handle 401 like we'd normally do!
super.onReceivedHttpAuthRequest(view, handler, host, realm);
}
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ // For Android >= 5.0
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ Log.i("mytag", "onActivityResult (For Android >= 5.0)");
+ // If RequestCode or Callback is Invalid
+ if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
+ super.onActivityResult(requestCode, resultCode, intent);
+ return;
+ }
+ mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
+ mUploadCallbackLollipop = null;
+ }
+ // For Android < 5.0
+ else {
+ Log.i("mytag", "onActivityResult (For Android < 5.0)");
+ // If RequestCode or Callback is Invalid
+ if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
+ super.onActivityResult(requestCode, resultCode, intent);
+ return;
+ }
+
+ if (null == mUploadCallback) return;
+ Uri result = intent == null || resultCode != cordova.getActivity().RESULT_OK ? null : intent.getData();
+
+ mUploadCallback.onReceiveValue(result);
+ mUploadCallback = null;
+ }
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org