Android WebView 网页实现选择文件

android webView示例代码(使用时打开本地html跨域、type=file 选择文件打不开问题) 1、 当我使用 android webview 打开本地 html 时,页面的 layui 的路由 使用 ajax 读取html、less文件采用了发请求的方式,所以出现了跨域问题。2、h5 type=file 选择文件打不开。 阅读详情

通常网页上都会有选择文件上传按钮 代码为 < input type=”file” />

要顺利的打开本地文件夹,就要重新写openFileChooser,然后再研究中发现openFileChooser是隐藏的一个方法,不能继承重写。

如下是解决方案:

1、

2、new 一个WebChromeClient,重新实现 openFileChooser方法

webView.setWebChromeClient(new WebChromeClient()
{
    public void openFileChooser(ValueCallback<Uri> filePathCallback)
    {
        mFilePathCallback4 = filePathCallback;
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
    }

    public void openFileChooser(ValueCallback filePathCallback, String acceptType)
    {
        mFilePathCallback4 = filePathCallback;
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
    }

    public void openFileChooser(ValueCallback<Uri> filePathCallback, String acceptType, String capture)
    {
        mFilePathCallback4 = filePathCallback;
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
    }

    @Override
    public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
    {
        mFilePathCallback5 = filePathCallback;
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
        return true;
    }
});

3、设置回调

private static final int REQUEST_FILE_PICKER = 1;
private ValueCallback<Uri> mFilePathCallback4;
private ValueCallback<Uri[]> mFilePathCallback5;

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    if(requestCode==REQUEST_FILE_PICKER)
    {
        if(mFilePathCallback4!=null)
        {
            Uri result = intent==null || resultCode!=Activity.RESULT_OK ? null : intent.getData();
            if(result!=null)
            {
                String path = MediaUtility.getPath(getActivity(), result);
                Uri uri = Uri.fromFile(new File(path));
                mFilePathCallback4.onReceiveValue(uri);
            }
            else
            {
                mFilePathCallback4.onReceiveValue(null);
            }
        }
        if(mFilePathCallback5!=null)
        {
            Uri result = intent==null || resultCode!=Activity.RESULT_OK ? null : intent.getData();
            if(result!=null)
            {
                String path = MediaUtility.getPath(getActivity(), result);
                Uri uri = Uri.fromFile(new File(path));
                mFilePathCallback5.onReceiveValue(new Uri[]{ uri });
            }
            else
            {
                mFilePathCallback5.onReceiveValue(null);
            }
        }

        mFilePathCallback4 = null;
        mFilePathCallback5 = null;
    }
}
android中WebView中H5或者JS选择android本地文件 1,首先自定义WebChromeClient (这里项目需要只选择图片及文档文案) package test.demo.bean; import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.webkit.PermissionRequest;. 阅读详情

相关推荐

机器视觉最全面试题总结

空洞卷积(Atrous Convolution)也叫做膨胀卷积、扩张卷积,最初的提出是为了解决图像分割在用下采样(池化、卷积)增加感受野时带来的特征图缩小,后再上采样回去时造成的精度上的损失。空洞卷积通过引入了一个扩张率的超参数,该参数定义了卷积核处理数据时各值的间距。可以在增加感受野的同时保持特征图的尺寸不变,从而代替下采样和上采样a. 是普通的卷积过程(dilation rate = 1),卷积后的感受野为3b. 是dilation rate = 2的空洞卷积,卷积后的感受野为5。

@bangbang的博客 9234

Android webview点击<input type=“file“>选择文件的实现

在安卓webview中实现选择文件的功能

flyinmind的专栏 3330

深度解析跨境支付之业务架构

详解跨境支付之业务架构

weixin_47493863的博客 1889

android webview 选择图片上传,适配Android WebView支持上传图片,视频

问题原因:H5访问本地文件的时候, 使用的 ,WebView 出于安全性的考虑,是限制了以上操作。解决办法:重写 WebviewChromeClient 中的 openFileChooser() 和 onShowFileChooser()方法响应,然后使用原生代码来实现调用本地相册和拍照的功能,最后在 onActiivtyResult 把选择的图片 URI 回传给 WebviewChromeCli...

weixin_39928017的博客 813

别再让CPU干GPU的活了:CST Studio Suite GPU加速深度调优指南(从驱动版本到任务管理器监控)

本文深入探讨了CST Studio Suite的GPU加速深度调优方法,从NVIDIA驱动版本选择到系统级资源管理,再到实时监控与瓶颈诊断技术。通过科学的驱动优化、GPU资源管理策略和高级调优技巧,显著提升仿真效率,特别适合电磁仿真工程师和硬件加速需求的专业用户。

weixin_28740299的博客 172

Xilinx XDMA IP核配置实战:AXI Memory Mapped vs Stream选型指南(附PCIe调试技巧)

本文深入解析Xilinx XDMA IP核配置中AXI Memory Mapped与AXI Stream两种DMA接口的核心区别与选型策略。针对PCIe高速数据传输场景,详细对比了二者在数据特性、延迟、硬件资源及软件复杂度上的差异,为FPGA工程师在数据采集、实时处理等项目中做出高效设计决策提供实战指南,并附有关键的PCIe调试技巧。

qsc901234的博客 587

安卓WebView调起本地文件选择

场景:有时使用后台给的H5或者第三方SDK比如蚂蚁智能客服,当用webview去加载所给的H5中有上传本地文件时,点击上传按钮无反应。 我用的是github上开源的AgentWeb(也可直接使用WebView) AgentVIew的用法很简单,这里就不赘述了。 关键点: 1、给WebVIew设置WebChromeClient时注意实现以下几个方法 private ValueCallback<Uri> mUploadMessage; private ValueCallback<U

lunious的博客 1933

uniapp实现app版本发现新版本后,自动更新

app实现自动更新

oldolder的博客 1287

Android使用WebView加载网页选择文件上传

文章目录效果如下:网页参考代码Android代码 效果如下: 使用Android WebView加载网页,网页中调用文件选择功能实现 网页参考代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,maximun-scale=1,mininum-scale=1,user-scale=1"> &l

这个杀手不太累的博客 5785

HDMI 2.1超高清传输背后的“隐形功臣”:深入浅出图解VESA DSC压缩核心流程

本文深入解析HDMI 2.1超高清传输中的VESA DSC压缩技术,揭示其如何在不损失画质的前提下实现带宽减半。通过切片并行处理和智能算法,DSC技术有效解决了8K/4K高帧率视频的传输瓶颈,成为现代显示设备不可或缺的“隐形功臣”。

weixin_30615767的博客 428

ios开发拒绝“玄学”Crash:从循环引用到脏内存,构建你的系统性排查思维模型

你申请了内存,写了数据,这块内存就是脏的。系统无法直接回收它,除非你显式释放,或者系统把它 swap 出去(但在 iOS 上,Compressed Memory 机制虽然能压缩,但不会像桌面系统那样频繁 swap 到磁盘,一旦压缩内存也撑不住,你也得挂)。所以,排查 OOM 的核心心法只有一条:不要问“哪里漏了”,要问“每一刻,留在这个页面上的内存,凭什么必须在这里?一旦内存水位线逼近阈值(不同机型不同,老机器可能 600MB 就危,新机器能抗 1.5GB),系统发个警告。

大模型大数据攻城狮的专栏 731

Android中WebView网页上传文件设置

文章目录功能webView#setWebChromeClient 功能 在webView加载的网页中选择文件可以正常调用原生的选择文件功能 webView#setWebChromeClient public class MainActivity extends AppCompatActivity { private WebView webView; private ValueC...

这个杀手不太累的博客 1536

AD9361功能介绍和使用

AD9361使用分数分频锁相环(PLL)来产生发射机和接收机本地振荡器(LO)频率和BB PLL。BB PLL 可用于数据转换、数字滤波器和 |/O 端口。PLL的参考时钟可以由外部振荡器或外部晶体(XO)和数字可编程片内可变电容提供,电容微调产生参考时钟频率,XO和微调电容的组合统称为DCXO。有多个天线输入的分集系统。接收链数据首先经过低噪声放大器(LNA),然后是同相(1)和正交(Q)放大器,混频器和频带整形滤波器,可将接收到的信号下变频为基带以进行数字化。时分双工(TDD)和频分双工(FDD)。。。

wangjie36的博客 1万+

Android WebView加载H5网页通过WebChromeClient选择设备文件

Android WebView加载H5网页通过WebChromeClient选择设备文件 先写一个web.html作为测试网页文件放到res/assets目录下: &lt;html&gt; &lt;body&gt; &lt;input type="file" value="选择文件"&gt; &lt;/body&gt; &lt;/html&gt;   package zhang

Zhang Phil 2002

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

android使用webview上传文件,Android项目中如何在webview页面中上传文件

Android项目中如何在webview页面中上传文件发布时间:2020-11-26 15:56:27来源:亿速云阅读:68作者:Leah本篇文章为大家展示了Android项目中如何在webview页面中上传文件,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。Android webview在默认情况下是不支持网页中的文件上传功能的;如果在网页中有,在andr...

weixin_35995661的博客 1047

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

android webview 多文件上传,让Android中的webview支持页面中的文件上传

android webview在默认情况下是不支持网页中的文件上传功能的;如果在网页中有,在android webview中访问时也会出现浏览文件的按钮但是点击按钮之后没有反应...那么如何能够让android的webview能够响应,这个浏览按钮呢?我们需要为webview设置WebChromeClient,在WebChromeClient的实现类中覆盖文件选择的方法:/************...

weixin_30249997的博客 526

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Android WebView 选择图片

Android WebView 选择图片 public static final int SELECT_IMAGE_REQUEST_CODE = 1000; private WebView mWebView; private ValueCallback<Uri[]> mValueCallback; private void setWeb() { mWebView.loadUrl(url); WebSettings webSettings = mWebView.getSettin

MAIMIHO的博客 1051

android使用webview上传文件,Android中的webview支持页面中的文件上传实例代码

Android webview在默认情况下是不支持网页中的文件上传功能的;如果在网页中有,在android webview中访问时也会出现浏览文件的按钮但是点击按钮之后没有反应...那么如何能够让android的webview能够响应,这个浏览按钮呢?在网上查了很多资料,很多相同的,但都漏掉了一个地方,导致无法读取到文件的完整地址(“c:\upfile\233232.jpg”),整理最终代码入下:...

weixin_42392054的博客 374

android webview 多文件上传,Android中的webview支持页面中的文件上传实例代码

Android webview在默认情况下是不支持网页中的文件上传功能的;如果在网页中有,在android webview中访问时也会出现浏览文件的按钮但是点击按钮之后没有反应...那么如何能够让android的webview能够响应,这个浏览按钮呢?在网上查了很多资料,很多相同的,但都漏掉了一个地方,导致无法读取到文件的完整地址(“c:\upfile\233232.jpg”),整理最终代码入下:...

weixin_39684898的博客 120

Android之WebView加载网页与JS交互使用

前言:我在做WebView加载网页时,可能会出现未知的各种错误情况,所以在xml布局时,是不会直接把WebView控件写在xml布局中的额,为了防止对webview的引用无法断开,所以我在布局写一个布局容器,比如:LinearLayout,然后在代码中动态的创建WebView控件,然后添加到容器布局LinearLayout中,然后在activity的生命周期中onDestory() 方法中把W...

文艺范的博客 1086

Android WebView 拍照和选择图片

转载地址:https://www.jianshu.com/p/13f4b8f70947 Android WebView 嵌套网页中有js调取拍照和选择图片上传的功能,这个需要在我们的代码中去实现方法 首先基础WebView设置 WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEn...

baidu_21088845的博客 519
上一篇: OPenfire源码环境配置和编译
下一篇: 视频格式与视频编码压缩标准 之间的关系
春水煎茶
博客等级 码龄14年 11粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值