1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (mUploadMessage == null && mUploadCallbackAboveL == null) { return; }
switch (requestCode) { case RESULT_FILE_CHOOSE: Uri result = data == null || resultCode != RESULT_OK ? null : data.getData(); if (mUploadCallbackAboveL != null) { Uri[] results = null; if (data != null) { String dataString = data.getDataString(); ClipData clipData = data.getClipData();
if (clipData != null) { results = new Uri[clipData.getItemCount()]; for (int i = 0; i < clipData.getItemCount(); i++) { ClipData.Item item = clipData.getItemAt(i); results[i] = item.getUri(); } }
if (dataString != null) { results = new Uri[]{Uri.parse(dataString)}; } }
mUploadCallbackAboveL.onReceiveValue(results); mUploadCallbackAboveL = null; } else if (mUploadMessage != null) { mUploadMessage.onReceiveValue(result); mUploadMessage = null; } break; } }
public class MyWebChromeClient extends WebChromeClient { public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), RESULT_FILE_CHOOSE); }
public void openFileChooser( ValueCallback uploadMsg, String acceptType ) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), RESULT_FILE_CHOOSE); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){ mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult( Intent.createChooser( i, "File Browser" ), RESULT_FILE_CHOOSE ); } public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { mUploadCallbackAboveL = filePathCallback; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), RESULT_FILE_CHOOSE); return true; } }
|