android webview choose file to upload

Overview

Android WebView文件上传

本工程为大家演示在H5中如何上传文件,同时也提供了服务端代码,有兴趣的读者可以部署起来,测试文件上传功能。

如果只对客户端部分感兴趣,只需要关注WebView文件选择部分即可

服务端代码下载地址, 客户端可以用如下url来上传文件 http://your ip address:port/AndroidMvvmServer/upload,如 http://192.168.1.200:8080/AndroidMvvmServer/upload

经过测试的机型

厂商 机型 系统版本
三星 GalaxyS4 Android5.0.1
小米 红米4 Android6.0.1
华为 荣耀7I Android6.0.1
华为 荣耀V8 Android8.0
华为 Mate20 Android9.0

在华为荣耀某台机器上(Android5.0)上,文件选择效果如下所示:

Android5.1

Android4.4版本中, 如果使用系统默认的文件选择器,使用相册来选择文件而不是文件选项来选择文件 可能会遇到不能正确获取到选择的文件名. 如下图所示:

android4.4

不同手机厂商手机默认的文件选择器

在红米手机上Android6.0(左) 和 华为荣耀7IAndroid6.0(右),WebView文件选择效果如下所示:

红米手机上 Android6.0

自定义WebView文件选择器

不同的手机定制厂商对WebView文件选择器不管是在样式上还是按钮个数上都不尽相同。

如果需要统一WebView文件选择样式,需要自定义WebView文件选择器,如下图所示:

自定义选择器

需要注意的问题

1,如果在使用的过程中,或者在此基础上进行修改的过程中 ,出现H5的中的选择文件按钮点击没有反应,可能是ValueCallback没有重置导致的。

2,本项目主要处理H5文件选择的问题,关于权限、文件存储的目录可以自行根据实际情况修改

APK Demo下载地址

引用文档

  1. chromium-webview-samples
  2. file-upload-in-webview
You might also like...
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Android client for ProjectRTC - a WebRTC demo

AndroidRTC WebRTC Live Streaming An Android client for ProjectRTC. It is designed to demonstrate WebRTC video calls between androids and/or desktop br

IceNet - Fast, Simple and Easy Networking for Android

IceNet FAST, SIMPLE, EASY This library is an Android networking wrapper consisting of a combination of Volley, OkHttp and Gson. For more information s

Easy, asynchronous, annotation-based SOAP for Android

IceSoap IceSoap provides quick, easy, asynchronous access to SOAP web services from Android devices. It allows for SOAP responses to be bound to Java

Run Node.js on Android by rewrite Node.js in Java

node-android Run Node.js on Android by rewrite Node.js in Java with the compatible API. third-party: libuvpp, libuv-java JNI code by Oracle. Build Clo

dns library for android

Qiniu Happy DNS for Android 安装 直接安装 通过maven 使用方法 DnsManager 可以创建一次,一直使用。 IResolver[] resolvers = new IResolver[3]; resolvers[0] = AndroidDnsSe

HTTP Server for Android Instrumentation tests

RESTMock REST API mocking made easy. RESTMock is a library working on top of Square's okhttp/MockWebServer. It allows you to specify Hamcrest matchers

🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

Owner
yuzhiqiangqiangqiang
yuzhiqiangqiangqiang
Android 中 WebView 与原生通信

JsBridge SDK支持 Js调用原生方法并支持异步回调和同步回调 原生调用Js方法并支持异步回调 Js调用名称空间可自由配置,统一管理命名空间 支持Js调用原生方法多次回调,如果不想多次回调可以删除回调方法 支持部分Js框架中window并非顶级window API介绍 callJsFunct

null 29 Dec 28, 2022
The best file downloader library for Android

Overview Fetch is a simple, powerful, customizable file download manager library for Android. Features Simple and easy to use API. Continuous download

Tonyo Francis 1.5k Jan 8, 2023
Async file downloader for Android

What is FileBox FileBox is an async file downloader library for Android. Before we develop filebox, we though that URL content changes very rarely. So

Lyrebird Studio 311 Dec 25, 2022
Utilizes the Range HTTP header to download a file with multiple connections in parallel, bypassing cheap bandwidth throttling

async-range-downloader Utilizes the Range HTTP header to download a file with multiple connections in parallel, bypassing cheap bandwidth throttling T

Torben 4 Apr 12, 2022
An App to download a file from Internet by clicking on a custom-built button

LoadApp LoadApp is an app to download a file from the Internet by clicking on a custom-built button where: Width of the button gets animated from left

Anas Tariq 2 Aug 29, 2022
:satellite: [Android Library] Simplified async networking in android

Android library that simplifies networking in android via an async http client. Also featured in [Awesome Android Newsletter #Issue 15 ] Built with ❤︎

Nishant Srivastava 36 May 14, 2022
Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

VK.com 104 Dec 12, 2022
Android Easy Http - Simplest android http request library.

Android Easy Http Library 繁體中文文檔 About Android Easy Http Library Made on OkHttp. Easy to do http request, just make request and listen for the respons

null 13 Sep 30, 2022
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Koushik Dutta 6.3k Dec 27, 2022