项目中使用 WebView 加载了一个页面,现在需要在安卓中把一个File对象传输到H5中使用,就像使用<input type="file"/>那样,可以通过input.files[0]获取到H5的File对象(它不会将文件读取到内存中),目前传输文件只能通过input方式,但是必须要用户点击才能触发。
<android.webkit.WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints"
android:background="#FFFFFF" />
需要获取这样的对象:
- 怎么才能不通过input方式直接传入File引用对象?目前只找到用base64字符串和fetch的方式,但他们都会将文件读取到内存中。
用ContentProvider和自定义协议:
然后在H5页面里: