diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java index 9f6ffd9c..315025fe 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -24,8 +24,12 @@ import org.json.JSONArray; import org.json.JSONException; import android.annotation.TargetApi; +import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.View; @@ -33,6 +37,7 @@ import android.view.ViewGroup.LayoutParams; import android.webkit.ConsoleMessage; import android.webkit.JsPromptResult; import android.webkit.JsResult; +import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebStorage; import android.webkit.WebView; @@ -47,6 +52,8 @@ import android.widget.RelativeLayout; */ public class CordovaChromeClient extends WebChromeClient { + public static final int FILECHOOSER_RESULTCODE = 5173; + private static final String LOG_TAG = "CordovaChromeClient"; private String TAG = "CordovaLog"; private long MAX_QUOTA = 100 * 1024 * 1024; private CordovaInterface cordova; @@ -55,6 +62,9 @@ public class CordovaChromeClient extends WebChromeClient { // the video progress view private View mVideoProgressView; + // File Chooser + public ValueCallback mUploadMessage; + /** * Constructor. * @@ -369,5 +379,21 @@ public class CordovaChromeClient extends WebChromeClient { } return mVideoProgressView; } + + public void openFileChooser(ValueCallback uploadMsg) { + this.openFileChooser(uploadMsg, "*/*"); + } + public void openFileChooser( ValueCallback uploadMsg, String acceptType ) { + mUploadMessage = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + this.cordova.getActivity().startActivityForResult(Intent.createChooser(i, "File Browser"), + FILECHOOSER_RESULTCODE); + } + + public ValueCallback getValueCallback() { + return this.mUploadMessage; + } } diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 547a450d..44c9299a 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -333,6 +333,10 @@ public class CordovaWebView extends WebView { this.chromeClient = client; super.setWebChromeClient(client); } + + public CordovaChromeClient getWebChromeClient() { + return this.chromeClient; + } /** * Load the url into the webview. diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index bd1cf791..2299fb70 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -38,6 +38,7 @@ import android.content.Intent; import android.content.res.Configuration; import android.graphics.Color; import android.media.AudioManager; +import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.util.Log; @@ -49,6 +50,8 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.webkit.ValueCallback; +import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.LinearLayout; @@ -190,6 +193,7 @@ public class DroidGap extends Activity implements CordovaInterface { private String initCallbackClass; + private Object LOG_TAG; /** * Sets the authentication token. @@ -818,6 +822,19 @@ public class DroidGap extends Activity implements CordovaInterface { protected void onActivityResult(int requestCode, int resultCode, Intent intent) { LOG.d(TAG, "Incoming Result"); super.onActivityResult(requestCode, resultCode, intent); + Log.d(TAG, "Request code = " + requestCode); + ValueCallback mUploadMessage = this.appView.getWebChromeClient().getValueCallback(); + if (requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) { + Log.d(TAG, "did we get here?"); + if (null == mUploadMessage) + return; + Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData(); + Log.d(TAG, "result = " + result); +// Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this)); +// Log.d(TAG, "result = " + filepath); + mUploadMessage.onReceiveValue(result); + mUploadMessage = null; + } CordovaPlugin callback = this.activityResultCallback; if(callback == null) { @@ -869,8 +886,7 @@ public class DroidGap extends Activity implements CordovaInterface { final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP); me.runOnUiThread(new Runnable() { public void run() { - if (exit) - { + if (exit) { me.appView.setVisibility(View.GONE); me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit); }