├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── inputfilesample │ │ └── android │ │ └── chrome │ │ └── google │ │ └── com │ │ └── inputfilesample │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── www │ │ ├── bower_components │ │ └── modernizr │ │ │ └── modernizr.custom.72986.js │ │ ├── fonts │ │ ├── Lobster_Two │ │ │ ├── LobsterTwo-Bold.ttf │ │ │ ├── LobsterTwo-BoldItalic.ttf │ │ │ ├── LobsterTwo-Italic.ttf │ │ │ ├── LobsterTwo-Regular.ttf │ │ │ └── OFL.txt │ │ └── Londrina_Shadow │ │ │ ├── LondrinaShadow-Regular.ttf │ │ │ └── OFL.txt │ │ ├── images │ │ └── arrow.png │ │ ├── index.html │ │ ├── index2.html │ │ ├── scripts │ │ └── main.js │ │ └── styles │ │ └── main.css │ ├── java │ └── com │ │ └── chiclaim │ │ └── webview │ │ ├── AppChooserActivity.java │ │ ├── AppChooserFragment.java │ │ ├── CustomChooserActivity.java │ │ └── MainActivity.java │ └── res │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ ├── ic_album.png │ ├── ic_camera.png │ └── ic_launcher.png │ ├── layout │ ├── app_chooser_activity.xml │ ├── app_chooser_fragment.xml │ ├── custom_chooser_activity_layout.xml │ ├── dialog_chooser_layout.xml │ └── main_activity.xml │ ├── menu │ └── main.xml │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── assets ├── demo.apk └── www │ ├── android4.4.gif │ ├── bower_components │ └── modernizr │ │ └── modernizr.custom.72986.js │ ├── custom_chooser.gif │ ├── emulator5.0.gif │ ├── fonts │ ├── Lobster_Two │ │ ├── LobsterTwo-Bold.ttf │ │ ├── LobsterTwo-BoldItalic.ttf │ │ ├── LobsterTwo-Italic.ttf │ │ ├── LobsterTwo-Regular.ttf │ │ └── OFL.txt │ └── Londrina_Shadow │ │ ├── LondrinaShadow-Regular.ttf │ │ └── OFL.txt │ ├── images │ └── arrow.png │ ├── index.html │ ├── scripts │ └── main.js │ ├── styles │ └── main.css │ └── xiaomi-vs-huawei.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | #*.apk 3 | #.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | *.idea 35 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Android WebView文件上传 2 | 3 | 本工程为大家演示在H5中如何上传文件,同时也提供了服务端代码,有兴趣的读者可以部署起来,测试文件上传功能。 4 | 5 | 如果只对客户端部分感兴趣,只需要关注WebView文件选择部分即可 6 | 7 | [服务端代码下载地址](https://github.com/chiclaim/android_mvvm_server), 客户端可以用如下url来上传文件 8 | http://`your ip address`:`port`/AndroidMvvmServer/upload,如 http://192.168.1.200:8080/AndroidMvvmServer/upload 9 | 10 | 11 | ### 经过测试的机型 12 | 13 | | 厂商 | 机型 | 系统版本 | 14 | | -------- | -----: | :----: | 15 | | 三星 | GalaxyS4 | Android5.0.1 | 16 | | 小米 | 红米4 | Android6.0.1 | 17 | | 华为 | 荣耀7I | Android6.0.1 | 18 | | 华为 | 荣耀V8 | Android8.0 | 19 | | 华为 | Mate20 | Android9.0 | 20 | 21 | 22 | 在华为荣耀某台机器上(Android5.0)上,文件选择效果如下所示: 23 | 24 | ![Android5.1](https://github.com/chiclaim/android-webview-upload-file/blob/master/assets/www/emulator5.0.gif) 25 | 26 | 在`Android4.4`版本中, 如果使用`系统默认的文件选择器`,使用`相册`来选择文件而不是`文件`选项来选择文件 可能会遇到不能正确获取到选择的文件名. 如下图所示: 27 | 28 | ![android4.4](https://github.com/chiclaim/android-webview-upload-file/blob/master/assets/www/android4.4.gif) 29 | 30 | ### 不同手机厂商手机默认的文件选择器 31 | 32 | 在红米手机上Android6.0(左) 和 华为荣耀7IAndroid6.0(右),WebView文件选择效果如下所示: 33 | 34 | ![红米手机上 Android6.0](https://github.com/chiclaim/android-webview-upload-file/blob/master/assets/www/xiaomi-vs-huawei.gif) 35 | 36 | 37 | ### 自定义WebView文件选择器 38 | 39 | 不同的手机定制厂商对WebView文件选择器不管是在样式上还是按钮个数上都不尽相同。 40 | 41 | 如果需要统一WebView文件选择样式,需要自定义WebView文件选择器,如下图所示: 42 | 43 | ![自定义选择器](https://github.com/chiclaim/android-webview-upload-file/blob/master/assets/www/custom_chooser.gif) 44 | 45 | 46 | 47 | ### 需要注意的问题 48 | 49 | 1,如果在使用的过程中,或者在此基础上进行修改的过程中 ,出现H5的中的`选择文件`按钮点击没有反应,可能是`ValueCallback`没有重置导致的。 50 | 51 | 2,本项目主要处理H5文件选择的问题,关于权限、文件存储的目录可以自行根据实际情况修改 52 | 53 | [APK Demo下载地址](https://github.com/chiclaim/android-webview-upload-file/blob/master/assets/demo.apk) 54 | 55 | ### 引用文档 56 | 1. [chromium-webview-samples](https://github.com/GoogleChrome/chromium-webview-samples) 57 | 2. [file-upload-in-webview](http://stackoverflow.com/questions/5907369/file-upload-in-webview) 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.0.0" 6 | 7 | defaultConfig { 8 | applicationId "com.chiclaim.webview" 9 | minSdkVersion 15 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | //runProguard false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/mattgaunt/Programming/Tools/android-sdk_1518674_mac-x86/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/inputfilesample/android/chrome/google/com/inputfilesample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package inputfilesample.android.chrome.google.com.inputfilesample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/assets/www/bower_components/modernizr/modernizr.custom.72986.js: -------------------------------------------------------------------------------- 1 | /* Modernizr 2.6.2 (Custom Build) | MIT & BSD 2 | * Build: http://modernizr.com/download/#-shiv-cssclasses-prefixed-testprop-testallprops-domprefixes-load 3 | */ 4 | ;window.Modernizr=function(a,b,c){function x(a){j.cssText=a}function y(a,b){return x(prefixes.join(a+";")+(b||""))}function z(a,b){return typeof a===b}function A(a,b){return!!~(""+a).indexOf(b)}function B(a,b){for(var d in a){var e=a[d];if(!A(e,"-")&&j[e]!==c)return b=="pfx"?e:!0}return!1}function C(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:z(f,"function")?f.bind(d||b):f}return!1}function D(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),e=(a+" "+n.join(d+" ")+d).split(" ");return z(b,"string")||z(b,"undefined")?B(e,b):(e=(a+" "+o.join(d+" ")+d).split(" "),C(e,b,c))}var d="2.6.2",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m="Webkit Moz O ms",n=m.split(" "),o=m.toLowerCase().split(" "),p={},q={},r={},s=[],t=s.slice,u,v={}.hasOwnProperty,w;!z(v,"undefined")&&!z(v.call,"undefined")?w=function(a,b){return v.call(a,b)}:w=function(a,b){return b in a&&z(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=t.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(t.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(t.call(arguments)))};return e});for(var E in p)w(p,E)&&(u=E.toLowerCase(),e[u]=p[E](),s.push((e[u]?"":"no-")+u));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)w(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},x(""),i=k=null,function(a,b){function k(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function l(){var a=r.elements;return typeof a=="string"?a.split(" "):a}function m(a){var b=i[a[g]];return b||(b={},h++,a[g]=h,i[h]=b),b}function n(a,c,f){c||(c=b);if(j)return c.createElement(a);f||(f=m(c));var g;return f.cache[a]?g=f.cache[a].cloneNode():e.test(a)?g=(f.cache[a]=f.createElem(a)).cloneNode():g=f.createElem(a),g.canHaveChildren&&!d.test(a)?f.frag.appendChild(g):g}function o(a,c){a||(a=b);if(j)return a.createDocumentFragment();c=c||m(a);var d=c.frag.cloneNode(),e=0,f=l(),g=f.length;for(;e",f="hidden"in a,j=a.childNodes.length==1||function(){b.createElement("a");var a=b.createDocumentFragment();return typeof a.cloneNode=="undefined"||typeof a.createDocumentFragment=="undefined"||typeof a.createElement=="undefined"}()}catch(c){f=!0,j=!0}})();var r={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,supportsUnknownElements:j,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:q,createElement:n,createDocumentFragment:o};a.html5=r,q(b)}(this,b),e._version=d,e._domPrefixes=o,e._cssomPrefixes=n,e.testProp=function(a){return B([a])},e.testAllProps=D,e.prefixed=function(a,b,c){return b?D(a,b,c):D(a,"pfx")},g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+s.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f 16 | 17 | 18 | 19 | 20 | Input File Demo 21 | 22 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/assets/www/index2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | H5文件上传 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/assets/www/scripts/main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * When the window loads, connect the showNotificationBtn to the Javascript 19 | * interface "window.NotificationBind" 20 | */ 21 | window.onload = function() { 22 | console.log('window.onload'); 23 | var loadFileBtn = document.querySelector('.loadFileBtn'); 24 | var fileInputField = document.querySelector('.hiddenFileInput'); 25 | var img = document.querySelector('img'); 26 | 27 | loadFileBtn.addEventListener('click', function() { 28 | fileInputField.click(); 29 | }.bind(this)); 30 | fileInputField.addEventListener('change', function(evt) { 31 | console.log('Change', evt); 32 | var reader = new FileReader(); 33 | reader.onload = function (evt) { 34 | img.src = evt.target.result; 35 | }; 36 | 37 | reader.readAsDataURL(evt.target.files[0]); 38 | }); 39 | }; -------------------------------------------------------------------------------- /app/src/main/assets/www/styles/main.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** Reference Local Fonts **/ 18 | @font-face { 19 | font-family: 'Lobster Two'; 20 | font-style: normal; 21 | font-weight: 400; 22 | src: local('Lobster Two'), local('LobsterTwo'), url('../fonts/Lobster_Two/LobsterTwo-Regular.ttf') format('truetype'); 23 | } 24 | 25 | @font-face { 26 | font-family: 'Londrina Shadow'; 27 | font-style: normal; 28 | font-weight: 400; 29 | src: local('Londrina Shadow'), local('LondrinaShadow-Regular'), url('../fonts/Londrina_Shadow/LondrinaShadow-Regular.ttf') format('truetype'); 30 | } 31 | 32 | html, body { 33 | width: 100%; 34 | height: 100%; 35 | min-height: 100%; 36 | margin: 0; 37 | padding: 0; 38 | font-size: 26px; 39 | 40 | overflow: hidden; 41 | } 42 | 43 | body { 44 | position: relative; 45 | font-family: 'Lobster Two', cursive; 46 | 47 | overflow: hidden; 48 | } 49 | 50 | h1, h2, h3, h4, h5, h6 { 51 | font-family: 'Londrina Shadow', cursive; 52 | } 53 | 54 | button { 55 | display: block; 56 | width: 100%; 57 | background-color: #f39c12; 58 | color: #fefefe; 59 | font-family: inherit; 60 | font-size: inherit; 61 | padding: 16px; 62 | margin: 0 auto; 63 | border-radius: 6px; 64 | border-style: none; 65 | border-bottom-style: solid; 66 | border-color: #E68F05; 67 | border-width: 4px; 68 | 69 | /** 70 | * Remove any touch feedback from WebView since 71 | * We handle the :active state 72 | */ 73 | outline: 0; 74 | -webkit-tap-highlight-color: rgba(0,0,0, 0.0); 75 | 76 | -webkit-user-select: none; 77 | user-select: none; 78 | } 79 | 80 | button:focus { 81 | background-color: #E68F05; 82 | border-color: #DA8300; 83 | } 84 | 85 | button:active { 86 | background-color: #FFA91F; 87 | border-color: #E68F05; 88 | } 89 | 90 | @media screen and (min-width: 500px) { 91 | button { 92 | width: 60%; 93 | } 94 | } 95 | 96 | @media screen and (min-width: 750px) { 97 | button { 98 | width: 40%; 99 | max-width: 400px; 100 | } 101 | } 102 | 103 | .hiddenFileInput { 104 | width: 0; 105 | height: 0; 106 | visibility: hidden; 107 | position: absolute; 108 | top: 0; 109 | left: 0; 110 | } 111 | 112 | .center { 113 | display: flex; 114 | flex-direction: column; 115 | 116 | width: 100%; 117 | height: 100%; 118 | 119 | align-items: center; 120 | justify-content: center; 121 | 122 | padding: 8px; 123 | 124 | box-sizing: border-box; 125 | } 126 | 127 | img { 128 | max-width: 100%; 129 | max-height: 60%; 130 | margin-bottom: 8px; 131 | } -------------------------------------------------------------------------------- /app/src/main/java/com/chiclaim/webview/AppChooserActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chiclaim.webview; 17 | 18 | import android.app.Activity; 19 | import android.os.Bundle; 20 | import android.util.Log; 21 | import android.view.Menu; 22 | import android.view.MenuItem; 23 | 24 | /** 25 | * WebView 选择文件上传,使用系统自带选择框 26 | */ 27 | public class AppChooserActivity extends Activity { 28 | 29 | private static final String TAG = AppChooserActivity.class.getSimpleName(); 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.app_chooser_activity); 35 | if (savedInstanceState == null) { 36 | Log.v(TAG, "AppChooserFragment Creation"); 37 | getFragmentManager().beginTransaction() 38 | .add(R.id.container, new AppChooserFragment()) 39 | .commit(); 40 | } 41 | } 42 | 43 | 44 | @Override 45 | public boolean onCreateOptionsMenu(Menu menu) { 46 | // Inflate the menu; this adds items to the action bar if it is present. 47 | getMenuInflater().inflate(R.menu.main, menu); 48 | return true; 49 | } 50 | 51 | @Override 52 | public boolean onOptionsItemSelected(MenuItem item) { 53 | // Handle action bar item clicks here. The action bar will 54 | // automatically handle clicks on the Home/Up button, so long 55 | // as you specify a parent activity in AndroidManifest.xml. 56 | int id = item.getItemId(); 57 | if (id == R.id.action_settings) { 58 | return true; 59 | } 60 | return super.onOptionsItemSelected(item); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/chiclaim/webview/AppChooserFragment.java: -------------------------------------------------------------------------------- 1 | package com.chiclaim.webview; 2 | 3 | import android.app.Activity; 4 | import android.app.Fragment; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.provider.MediaStore; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.webkit.ValueCallback; 15 | import android.webkit.WebChromeClient; 16 | import android.webkit.WebSettings; 17 | import android.webkit.WebView; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.text.SimpleDateFormat; 22 | import java.util.Date; 23 | 24 | public class AppChooserFragment extends Fragment { 25 | 26 | private static final String TAG = AppChooserFragment.class.getSimpleName(); 27 | 28 | public static final int REQUEST_CODE_LOLIPOP = 1; 29 | private final static int RESULT_CODE_ICE_CREAM = 2; 30 | 31 | private WebView mWebView; 32 | private ValueCallback mFilePathCallback; 33 | private String mCameraPhotoPath; 34 | 35 | private ValueCallback mUploadMessage; 36 | 37 | @Override 38 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 39 | Bundle savedInstanceState) { 40 | View rootView = inflater.inflate(R.layout.app_chooser_fragment, container, false); 41 | 42 | mWebView = (WebView) rootView.findViewById(R.id.fragment_main_webview); 43 | 44 | WebSettings settings = mWebView.getSettings(); 45 | settings.setJavaScriptEnabled(true); 46 | 47 | if (savedInstanceState != null) { 48 | mWebView.restoreState(savedInstanceState); 49 | } 50 | 51 | mWebView.setWebChromeClient(new WebChromeClient() { 52 | 53 | 54 | private void openFileChooser(String type) { 55 | Intent i = new Intent(Intent.ACTION_GET_CONTENT); 56 | i.addCategory(Intent.CATEGORY_OPENABLE); 57 | i.setType(type); 58 | startActivityForResult(Intent.createChooser(i, getString(R.string.file_chooser)), 59 | RESULT_CODE_ICE_CREAM); 60 | } 61 | 62 | private void onShowFileChooser(Intent cameraIntent) { 63 | //整个弹出框为:相机、相册、文件管理 64 | //如果安装了其他的相机、文件管理程序,也有可能会弹出 65 | //selectionIntent(相册、文件管理) 66 | //Intent selectionIntent = new Intent(Intent.ACTION_GET_CONTENT); 67 | //selectionIntent.addCategory(Intent.CATEGORY_OPENABLE); 68 | //selectionIntent.setType("image/*"); 69 | 70 | //------------------------------------ 71 | //如果通过下面的方式,则弹出的选择框有:相机、相册(Android9.0,Android8.0) 72 | //如果是小米Android6.0系统上,依然是:相机、相册、文件管理 73 | //如果安装了其他的相机(百度魔拍)、文件管理程序(ES文件管理器),也有可能会弹出 74 | Intent selectionIntent = new Intent(Intent.ACTION_PICK,null); 75 | selectionIntent.setType("image/*"); 76 | //------------------------------------ 77 | 78 | 79 | Intent[] intentArray; 80 | if (cameraIntent != null) { 81 | intentArray = new Intent[]{cameraIntent}; 82 | } else { 83 | intentArray = new Intent[0]; 84 | } 85 | 86 | Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); 87 | chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.file_chooser)); 88 | chooserIntent.putExtra(Intent.EXTRA_INTENT, selectionIntent); 89 | chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); 90 | 91 | startActivityForResult(chooserIntent, REQUEST_CODE_LOLIPOP); 92 | 93 | } 94 | 95 | 96 | //The undocumented magic method override 97 | //Eclipse will swear at you if you try to put @Override here 98 | // For Android 3.0+ 99 | public void openFileChooser(ValueCallback uploadMsg) { 100 | mUploadMessage = uploadMsg; 101 | openFileChooser("image/*"); 102 | } 103 | 104 | // For Android 3.0+ 105 | public void openFileChooser(ValueCallback uploadMsg, String acceptType) { 106 | mUploadMessage = uploadMsg; 107 | openFileChooser("*/*"); 108 | } 109 | 110 | //For Android 4.1 111 | public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { 112 | mUploadMessage = uploadMsg; 113 | openFileChooser("image/*"); 114 | } 115 | 116 | //For Android5.0+ 117 | public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { 118 | if (mFilePathCallback != null) { 119 | mFilePathCallback.onReceiveValue(null); 120 | } 121 | mFilePathCallback = filePathCallback; 122 | 123 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 124 | if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { 125 | // Create the File where the photo should go 126 | File photoFile = null; 127 | try { 128 | photoFile = createImageFile(); 129 | takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); 130 | } catch (IOException ex) { 131 | ex.printStackTrace(); 132 | } 133 | 134 | // Continue only if the File was successfully created 135 | if (photoFile != null) { 136 | mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); 137 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); 138 | } else { 139 | takePictureIntent = null; 140 | } 141 | } 142 | onShowFileChooser(takePictureIntent); 143 | return true; 144 | } 145 | }); 146 | 147 | // Load the local index.html file 148 | if (mWebView.getUrl() == null) { 149 | mWebView.loadUrl("file:///android_asset/www/index.html"); 150 | //mWebView.loadUrl("file:///android_asset/www/index2.html"); 151 | //mWebView.loadUrl("https://www.script-tutorials.com/demos/199/index.html"); 152 | //mWebView.loadUrl("http://192.168.1.109:8080/AndroidMvvmServer/upload"); 153 | } 154 | 155 | return rootView; 156 | } 157 | 158 | /** 159 | * More info this method can be found at 160 | * http://developer.android.com/training/camera/photobasics.html 161 | * 162 | * @return 163 | * @throws IOException 164 | */ 165 | private File createImageFile() throws IOException { 166 | // Create an image file name 167 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 168 | String imageFileName = "JPEG_" + timeStamp + "_"; 169 | File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 170 | File imageFile = File.createTempFile(imageFileName, ".jpg", storageDir); 171 | return imageFile; 172 | } 173 | 174 | @Override 175 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 176 | super.onActivityResult(requestCode, resultCode, data); 177 | 178 | switch (requestCode) { 179 | case RESULT_CODE_ICE_CREAM: 180 | Uri uri = null; 181 | if (data != null) { 182 | uri = data.getData(); 183 | } 184 | mUploadMessage.onReceiveValue(uri); 185 | mUploadMessage = null; 186 | break; 187 | case REQUEST_CODE_LOLIPOP: 188 | Uri[] results = null; 189 | // Check that the response is a good one 190 | if (resultCode == Activity.RESULT_OK) { 191 | if (data == null) { 192 | // If there is not data, then we may have taken a photo 193 | if (mCameraPhotoPath != null) { 194 | Log.d("AppChooserFragment", mCameraPhotoPath); 195 | 196 | results = new Uri[]{Uri.parse(mCameraPhotoPath)}; 197 | } 198 | } else { 199 | String dataString = data.getDataString(); 200 | if (dataString != null) { 201 | results = new Uri[]{Uri.parse(dataString)}; 202 | } 203 | } 204 | } 205 | 206 | mFilePathCallback.onReceiveValue(results); 207 | mFilePathCallback = null; 208 | break; 209 | } 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /app/src/main/java/com/chiclaim/webview/CustomChooserActivity.java: -------------------------------------------------------------------------------- 1 | package com.chiclaim.webview; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.content.DialogInterface; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Bundle; 9 | import android.os.Environment; 10 | import android.provider.MediaStore; 11 | import android.util.Log; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.webkit.ValueCallback; 15 | import android.webkit.WebChromeClient; 16 | import android.webkit.WebSettings; 17 | import android.webkit.WebView; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.text.SimpleDateFormat; 22 | import java.util.Date; 23 | 24 | /** 25 | * WebView 选择文件上传,自定义选择框 26 | */ 27 | public class CustomChooserActivity extends Activity { 28 | 29 | private static final int REQUEST_CODE_ALBUM = 1; 30 | private static final int REQUEST_CODE_CAMERA = 2; 31 | 32 | private WebView mWebView; 33 | 34 | private ValueCallback mFilePathCallback; 35 | 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.custom_chooser_activity_layout); 40 | mWebView = (WebView) findViewById(R.id.webview); 41 | WebSettings settings = mWebView.getSettings(); 42 | settings.setJavaScriptEnabled(true); 43 | 44 | initListener(); 45 | mWebView.loadUrl("file:///android_asset/www/index.html"); 46 | 47 | } 48 | 49 | private void initListener() { 50 | mWebView.setWebChromeClient(new WebChromeClient() { 51 | 52 | //For Android5.0+ 53 | public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { 54 | if (mFilePathCallback != null) { 55 | mFilePathCallback.onReceiveValue(null); 56 | } 57 | mFilePathCallback = filePathCallback; 58 | 59 | showChooserDialog(); 60 | return true; 61 | } 62 | }); 63 | 64 | } 65 | 66 | private Dialog dialog; 67 | private boolean resetCallback = true; 68 | 69 | private void showChooserDialog() { 70 | if (dialog == null) { 71 | dialog = new Dialog(this); 72 | dialog.setTitle(R.string.file_chooser); 73 | dialog.setContentView(R.layout.dialog_chooser_layout); 74 | 75 | //兼容android5.0.1 76 | // android5.0上dialog宽度变成了wrap_content 77 | if (dialog.getWindow() != null) { 78 | dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 79 | } 80 | 81 | dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 82 | @Override 83 | public void onDismiss(DialogInterface dialog) { 84 | if (resetCallback && mFilePathCallback != null) { 85 | mFilePathCallback.onReceiveValue(null); 86 | mFilePathCallback = null; 87 | } 88 | resetCallback = true; 89 | } 90 | }); 91 | 92 | dialog.findViewById(R.id.text_album).setOnClickListener(new View.OnClickListener() { 93 | @Override 94 | public void onClick(View v) { 95 | resetCallback = false; 96 | dialog.dismiss(); 97 | Intent albumIntent = new Intent(Intent.ACTION_PICK); 98 | albumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); 99 | startActivityForResult(albumIntent, REQUEST_CODE_ALBUM); 100 | } 101 | }); 102 | dialog.findViewById(R.id.text_camera).setOnClickListener(new View.OnClickListener() { 103 | @Override 104 | public void onClick(View v) { 105 | resetCallback = false; 106 | dialog.dismiss(); 107 | 108 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 109 | if (takePictureIntent.resolveActivity(getPackageManager()) != null) { 110 | File photoFile = null; 111 | try { 112 | photoFile = createImageFile(); 113 | } catch (IOException ex) { 114 | ex.printStackTrace(); 115 | } 116 | 117 | if (photoFile != null) { 118 | mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); 119 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); 120 | startActivityForResult(takePictureIntent, REQUEST_CODE_CAMERA); 121 | } 122 | } 123 | } 124 | }); 125 | } 126 | dialog.show(); 127 | } 128 | 129 | private File createImageFile() throws IOException { 130 | // Create an image file name 131 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 132 | String imageFileName = "JPEG_" + timeStamp + "_"; 133 | File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 134 | return File.createTempFile(imageFileName, ".jpg", storageDir); 135 | } 136 | 137 | 138 | private String mCameraPhotoPath; 139 | 140 | @Override 141 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 142 | super.onActivityResult(requestCode, resultCode, data); 143 | Uri[] results = null; 144 | if (resultCode == Activity.RESULT_OK) { 145 | switch (requestCode) { 146 | case REQUEST_CODE_ALBUM: 147 | if (data != null) { 148 | String dataString = data.getDataString(); 149 | if (dataString != null) { 150 | results = new Uri[]{Uri.parse(dataString)}; 151 | Log.d("CustomChooserActivity", dataString); 152 | } 153 | } 154 | break; 155 | case REQUEST_CODE_CAMERA: 156 | if (mCameraPhotoPath != null) { 157 | results = new Uri[]{Uri.parse(mCameraPhotoPath)}; 158 | Log.d("CustomChooserActivity", mCameraPhotoPath); 159 | } 160 | break; 161 | } 162 | } 163 | if (mFilePathCallback != null) { 164 | mFilePathCallback.onReceiveValue(results); 165 | mFilePathCallback = null; 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /app/src/main/java/com/chiclaim/webview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.chiclaim.webview; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class MainActivity extends Activity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.main_activity); 13 | } 14 | 15 | 16 | public void appChooser(View view) { 17 | startActivity(new Intent(this, AppChooserActivity.class)); 18 | } 19 | 20 | public void customChooser(View view) { 21 | startActivity(new Intent(this, CustomChooserActivity.class)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiclaim/android-webview-upload-file/68c3e6b7e028efd1f43f42f1e434f0e3cc240a07/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_album.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiclaim/android-webview-upload-file/68c3e6b7e028efd1f43f42f1e434f0e3cc240a07/app/src/main/res/drawable-xxhdpi/ic_album.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiclaim/android-webview-upload-file/68c3e6b7e028efd1f43f42f1e434f0e3cc240a07/app/src/main/res/drawable-xxhdpi/ic_camera.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiclaim/android-webview-upload-file/68c3e6b7e028efd1f43f42f1e434f0e3cc240a07/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/app_chooser_activity.xml: -------------------------------------------------------------------------------- 1 | 16 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_chooser_fragment.xml: -------------------------------------------------------------------------------- 1 | 16 | 20 | 21 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_chooser_activity_layout.xml: -------------------------------------------------------------------------------- 1 | 16 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_chooser_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 24 | 25 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/main_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 37 | 38 | 39 |
40 | 41 | 42 |
43 |
44 |

Notification Time

45 |
46 | 47 |

There should be a notification waiting for you...

48 |
49 |
50 | 51 |
52 |
53 |

You Clicked the Notification

54 |
55 |
56 |

There is only so much I can do with a notification you know...

57 |
58 |
59 | 60 |
61 |
62 |

Ssshhhhh

63 |
64 | 65 |
66 |

Secret Spot in the app, congrats :)

67 |
68 |
69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /assets/www/scripts/main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * When the window loads, connect the showNotificationBtn to the Javascript 19 | * interface "window.NotificationBind" 20 | */ 21 | window.onload = function() { 22 | console.log('window.onload'); 23 | var showNotificationBtn = document.querySelector('#show-notification-btn'); 24 | showNotificationBtn.addEventListener('click', function() { 25 | if(window.NotificationBind) { 26 | NotificationBind.showNotification('This is an Awesome notification'); 27 | } 28 | 29 | changeState(NOTIFICATION_SHOWN, true); 30 | }); 31 | 32 | updateUI(true); 33 | }; 34 | 35 | /** 36 | * From this point onwards, the Javascript is managing UI and 37 | * application state 38 | */ 39 | var animEndEventNames = { 40 | 'WebkitAnimation' : 'webkitAnimationEnd', 41 | 'OAnimation' : 'oAnimationEnd', 42 | 'msAnimation' : 'MSAnimationEnd', 43 | 'animation' : 'animationend' 44 | }; 45 | 46 | // animation end event name 47 | var animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ]; 48 | 49 | var NOTIFICATION_SHOWN = 0; 50 | var LAUNCH_FROM_NOTIFICATION = 1; 51 | var DEFAULT = 2; 52 | var SECRET_SCREEN = 3; 53 | 54 | var exports = {}; 55 | 56 | var currentState; 57 | var animating = false; 58 | 59 | function changeState(newState, animateForward) { 60 | console.log('changeState()'); 61 | 62 | if(animating || (newState == currentState)) { 63 | return; 64 | } 65 | 66 | var currentPage = document.querySelector('.current-page'); 67 | var newUI; 68 | 69 | var animCurrent = animateForward ? 'animate-to-left' : 'animate-to-right'; 70 | var animNew = animateForward ? 'animate-from-right' : 'animate-from-left'; 71 | 72 | var hash; 73 | 74 | switch(newState) { 75 | case NOTIFICATION_SHOWN: 76 | newUI = getNotifcationArrow(); 77 | hash = 'notification-shown'; 78 | break; 79 | case LAUNCH_FROM_NOTIFICATION: 80 | newUI = getLaunchFromNotificationUI(); 81 | hash = 'notification-launch'; 82 | break; 83 | case DEFAULT: 84 | newUI = getDefaultUI(); 85 | hash = ''; 86 | break; 87 | case SECRET_SCREEN: 88 | animCurrent = 'animate-to-right'; 89 | animNew = 'animate-from-left'; 90 | newUI = getSecretUI(); 91 | hash = 'secret'; 92 | break; 93 | } 94 | 95 | newUI.classList.add('current-page'); 96 | 97 | if(currentPage) { 98 | // We need to animate 99 | animating = true; 100 | 101 | currentPage.classList.add(animCurrent); 102 | newUI.classList.add(animNew); 103 | 104 | currentPage.addEventListener(animEndEventName, pageAnimationEnd(currentPage, newUI, animCurrent, animNew), false); 105 | } 106 | 107 | currentState = newState; 108 | 109 | pushState({}, "", hash); 110 | } 111 | 112 | function pageAnimationEnd(currentPage, newPage, animCurrent, animNew) { 113 | var animEndFunc = function() { 114 | currentPage.removeEventListener(animEndEventName, animEndFunc, false); 115 | 116 | currentPage.classList.remove(animCurrent); 117 | newPage.classList.remove(animNew); 118 | 119 | currentPage.classList.remove('current-page'); 120 | 121 | animating = false; 122 | }; 123 | return animEndFunc; 124 | } 125 | 126 | function getNotifcationArrow() { 127 | return document.querySelector('.notification-opened'); 128 | } 129 | 130 | function getLaunchFromNotificationUI() { 131 | return document.querySelector('.launched-from-notification'); 132 | } 133 | 134 | function getDefaultUI() { 135 | return document.querySelector('.init-screen'); 136 | } 137 | 138 | function getSecretUI() { 139 | return document.querySelector('.secret-screen'); 140 | } 141 | 142 | function updateUI(animateForward) { 143 | console.log('updateUI()'); 144 | var identifier = window.location.hash; 145 | var state; 146 | 147 | if(identifier == '#notification-launch') { 148 | state = LAUNCH_FROM_NOTIFICATION; 149 | } else if(identifier == '#notification-shown') { 150 | state = NOTIFICATION_SHOWN; 151 | } else if(identifier == '#secret') { 152 | state = SECRET_SCREEN; 153 | } else { 154 | state = DEFAULT; 155 | } 156 | 157 | changeState(state, animateForward); 158 | } 159 | 160 | function showSecretMessage() { 161 | var ui = getSecretUI(); 162 | if(ui.classList.contains('current-page')) { 163 | if(animating) { 164 | return; 165 | } 166 | window.history.back(); 167 | } else { 168 | changeState(SECRET_SCREEN); 169 | 170 | return 'You Found the Secret'; 171 | } 172 | } 173 | 174 | function pushState(state, title, path) { 175 | if(!path) { 176 | return; 177 | } 178 | 179 | window.location.hash = path; 180 | } 181 | 182 | window.onpopstate = function(event) { 183 | console.log('onpopstate()'); 184 | var popped = document.querySelector('.current-page') ? true : false; 185 | if(popped && currentState == SECRET_SCREEN) { 186 | popped = false; 187 | } 188 | updateUI(!popped); 189 | }; 190 | -------------------------------------------------------------------------------- /assets/www/styles/main.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** Reference Local Fonts **/ 18 | @font-face { 19 | font-family: 'Lobster Two'; 20 | font-style: normal; 21 | font-weight: 400; 22 | src: local('Lobster Two'), local('LobsterTwo'), url('../fonts/Lobster_Two/LobsterTwo-Regular.ttf') format('truetype'); 23 | } 24 | 25 | @font-face { 26 | font-family: 'Londrina Shadow'; 27 | font-style: normal; 28 | font-weight: 400; 29 | src: local('Londrina Shadow'), local('LondrinaShadow-Regular'), url('../fonts/Londrina_Shadow/LondrinaShadow-Regular.ttf') format('truetype'); 30 | } 31 | 32 | html, body { 33 | width: 100%; 34 | height: 100%; 35 | min-height: 100%; 36 | margin: 0; 37 | padding: 0; 38 | font-size: 26px; 39 | 40 | overflow: hidden; 41 | } 42 | 43 | body { 44 | position: relative; 45 | font-family: 'Lobster Two', cursive; 46 | color: #fefefe; 47 | 48 | overflow: hidden; 49 | } 50 | 51 | h1, h2, h3, h4, h5, h6 { 52 | font-family: 'Londrina Shadow', cursive; 53 | } 54 | 55 | header { 56 | display: flex; 57 | display: -webkit-box; 58 | 59 | align-items: center; 60 | -webkit-box-align: center; 61 | 62 | flex: 1; 63 | -webkit-box-flex: 1; 64 | } 65 | 66 | header > h1 { 67 | width: 100%; 68 | font-size: 60px; 69 | text-align: center; 70 | margin: 16px 0; 71 | } 72 | 73 | @media screen and (orientation: landscape) { 74 | header > h1 { 75 | font-size: 50px; 76 | } 77 | } 78 | 79 | button { 80 | display: block; 81 | width: 100%; 82 | background-color: #f39c12; 83 | color: inherit; 84 | font-family: inherit; 85 | font-size: inherit; 86 | padding: 16px; 87 | margin: 0 auto; 88 | border-radius: 6px; 89 | border-style: none; 90 | border-bottom-style: solid; 91 | border-color: #E68F05; 92 | border-width: 4px; 93 | 94 | /** 95 | * Remove any touch feedback from WebView since 96 | * We handle the :active state 97 | */ 98 | outline: 0; 99 | -webkit-tap-highlight-color: rgba(0,0,0, 0.0); 100 | 101 | -webkit-user-select: none; 102 | user-select: none; 103 | } 104 | 105 | button:focus { 106 | background-color: #E68F05; 107 | border-color: #DA8300; 108 | } 109 | 110 | button:active { 111 | background-color: #FFA91F; 112 | border-color: #E68F05; 113 | } 114 | 115 | @media screen and (min-width: 500px) { 116 | button { 117 | width: 60%; 118 | } 119 | } 120 | 121 | @media screen and (min-width: 750px) { 122 | button { 123 | width: 40%; 124 | max-width: 400px; 125 | } 126 | } 127 | 128 | .page-container { 129 | position: absolute; 130 | left: 0; 131 | top: 0; 132 | 133 | min-width: 100%; 134 | min-height: 100%; 135 | 136 | display: -webkit-box; 137 | display: flex; 138 | 139 | -webkit-box-orient: vertical; 140 | flex-direction: column; 141 | 142 | align-items: center; 143 | 144 | visibility: hidden; 145 | 146 | padding: 20px; 147 | box-sizing: border-box; 148 | background-color: #f1c40f; 149 | } 150 | 151 | .page-container.current-page { 152 | visibility: visible; 153 | } 154 | 155 | .page-container.notification-opened { 156 | background-color: #3498db; 157 | } 158 | 159 | @media screen and (orientation: landscape) { 160 | .page-container.notification-opened { 161 | -webkit-box-orient: horizontal; 162 | flex-direction: row; 163 | } 164 | 165 | .page-container.notification-opened > .notification-arrow { 166 | margin-right: 20px; 167 | } 168 | } 169 | 170 | .page-container.launched-from-notification { 171 | background-color: #1abc9c; 172 | } 173 | 174 | .page-container.secret-screen { 175 | background-color: #34495e; 176 | } 177 | 178 | .page-container > img { 179 | display: block; 180 | width: 25%; 181 | max-width: 200px; 182 | height: auto; 183 | } 184 | 185 | .main-content { 186 | display: flex; 187 | display: -webkit-box; 188 | 189 | align-items: center; 190 | -webkit-box-align: center; 191 | 192 | flex: 1; 193 | -webkit-box-flex: 1; 194 | 195 | flex-direction: column; 196 | -webkit-box-orient: vertical; 197 | } 198 | 199 | .main-content > p { 200 | width: 100%; 201 | text-align: center; 202 | } 203 | 204 | /** Handle the animations from left to right **/ 205 | .animate-to-left { 206 | -webkit-animation: moveToLeft .5s ease both; 207 | animation: moveToLeft .5s ease both; 208 | } 209 | 210 | .animate-to-right { 211 | -webkit-animation: moveToRight .5s ease both; 212 | animation: moveToRight .5s ease both; 213 | } 214 | 215 | .animate-from-right { 216 | -webkit-animation: moveFromRight .5s ease both; 217 | animation: moveFromRight .5s ease both; 218 | } 219 | 220 | .animate-from-left { 221 | -webkit-animation: moveFromLeft .5s ease both; 222 | animation: moveFromLeft .5s ease both; 223 | } 224 | 225 | @-webkit-keyframes moveToLeft { 226 | to { 227 | -webkit-transform: translateX(-100%); 228 | } 229 | } 230 | 231 | @keyframes moveToLeft { 232 | to { 233 | -webkit-transform: translateX(-100%); 234 | transform: translateX(-100%); 235 | } 236 | } 237 | 238 | @-webkit-keyframes moveToRight { 239 | to { -webkit-transform: translateX(100%); } 240 | } 241 | 242 | @keyframes moveToRight { 243 | to { 244 | -webkit-transform: translateX(100%); 245 | transform: translateX(100%); 246 | } 247 | } 248 | 249 | @-webkit-keyframes moveFromRight { 250 | from { -webkit-transform: translateX(100%); } 251 | } 252 | 253 | @keyframes moveFromRight { 254 | from { 255 | -webkit-transform: translateX(100%); 256 | transform: translateX(100%); 257 | } 258 | } 259 | 260 | @-webkit-keyframes moveFromLeft { 261 | from { -webkit-transform: translateX(-100%); } 262 | } 263 | 264 | @keyframes moveFromLeft { 265 | from { 266 | -webkit-transform: translateX(-100%); 267 | transform: translateX(-100%); 268 | } 269 | } -------------------------------------------------------------------------------- /assets/www/xiaomi-vs-huawei.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiclaim/android-webview-upload-file/68c3e6b7e028efd1f43f42f1e434f0e3cc240a07/assets/www/xiaomi-vs-huawei.gif -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.5.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chiclaim/android-webview-upload-file/68c3e6b7e028efd1f43f42f1e434f0e3cc240a07/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 25 11:27:01 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------