从图库中上传照片或在Webview中从相机拍摄 [英] Upload photo from gallery or take from camera in Webview
本文介绍了从图库中上传照片或在Webview中从相机拍摄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序是基于Web的,需要上传照片,网站上有一个文件输入按钮,我为此使用了它
My application is webbased and need to upload photos, website have a file input button, i made it work with this
wv = new WebView(this);
wv.setWebViewClient(new WebViewClient());
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.setWebChromeClient(new WebChromeClient()
{
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
MainActivity.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MainActivity.FILECHOOSER_RESULTCODE );
}
但是它只显示图库来挑选照片,我需要同时从相机拍摄.
but it shows just gallery to pick photos, i need to take from camera at the same time.
我尝试了此解决方案从webview上传相机照片和文件选择器输入字段,但只有打开的摄像头,没有上传拍摄的照片
i tried this solution Upload camera photo and filechooser from webview INPUT field but its only opening camera, not uploading taken photo
推荐答案
在您的示例中
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView v, String url) {
if (url.startsWith("testzapp:")) {
//do whatever action you had intended
}
}
}
这篇关于从图库中上传照片或在Webview中从相机拍摄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文