mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Initial input type=file support
This commit is contained in:
parent
0311f0db38
commit
a120614617
@ -24,8 +24,12 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -33,6 +37,7 @@ import android.view.ViewGroup.LayoutParams;
|
|||||||
import android.webkit.ConsoleMessage;
|
import android.webkit.ConsoleMessage;
|
||||||
import android.webkit.JsPromptResult;
|
import android.webkit.JsPromptResult;
|
||||||
import android.webkit.JsResult;
|
import android.webkit.JsResult;
|
||||||
|
import android.webkit.ValueCallback;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebStorage;
|
import android.webkit.WebStorage;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -47,6 +52,8 @@ import android.widget.RelativeLayout;
|
|||||||
*/
|
*/
|
||||||
public class CordovaChromeClient extends WebChromeClient {
|
public class CordovaChromeClient extends WebChromeClient {
|
||||||
|
|
||||||
|
public static final int FILECHOOSER_RESULTCODE = 5173;
|
||||||
|
private static final String LOG_TAG = "CordovaChromeClient";
|
||||||
private String TAG = "CordovaLog";
|
private String TAG = "CordovaLog";
|
||||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||||
private CordovaInterface cordova;
|
private CordovaInterface cordova;
|
||||||
@ -55,6 +62,9 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
// the video progress view
|
// the video progress view
|
||||||
private View mVideoProgressView;
|
private View mVideoProgressView;
|
||||||
|
|
||||||
|
// File Chooser
|
||||||
|
public ValueCallback<Uri> mUploadMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -370,4 +380,20 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
return mVideoProgressView;
|
return mVideoProgressView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
||||||
|
this.openFileChooser(uploadMsg, "*/*");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openFileChooser( ValueCallback<Uri> 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<Uri> getValueCallback() {
|
||||||
|
return this.mUploadMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,6 +334,10 @@ public class CordovaWebView extends WebView {
|
|||||||
super.setWebChromeClient(client);
|
super.setWebChromeClient(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CordovaChromeClient getWebChromeClient() {
|
||||||
|
return this.chromeClient;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the url into the webview.
|
* Load the url into the webview.
|
||||||
*
|
*
|
||||||
|
@ -38,6 +38,7 @@ import android.content.Intent;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -49,6 +50,8 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.webkit.ValueCallback;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
@ -190,6 +193,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
|
|
||||||
private String initCallbackClass;
|
private String initCallbackClass;
|
||||||
|
|
||||||
|
private Object LOG_TAG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the authentication token.
|
* Sets the authentication token.
|
||||||
@ -818,6 +822,19 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
LOG.d(TAG, "Incoming Result");
|
LOG.d(TAG, "Incoming Result");
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
|
Log.d(TAG, "Request code = " + requestCode);
|
||||||
|
ValueCallback<Uri> 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;
|
CordovaPlugin callback = this.activityResultCallback;
|
||||||
if(callback == null)
|
if(callback == null)
|
||||||
{
|
{
|
||||||
@ -869,8 +886,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
|
final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
|
||||||
me.runOnUiThread(new Runnable() {
|
me.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (exit)
|
if (exit) {
|
||||||
{
|
|
||||||
me.appView.setVisibility(View.GONE);
|
me.appView.setVisibility(View.GONE);
|
||||||
me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit);
|
me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user