webview,文件输入字段filechooser不显示 [英] webview, file input field filechooser doesn't show up

查看:80
本文介绍了webview,文件输入字段filechooser不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力尝试从网络视图上传文件.我尝试了许多解决方案,但没有一个起作用.

I have been working hard trying to upload files from a webview. I tried many solutions but none worked.

http://m0s-programming.blogspot.tw/2011/02/file-upload-in-through-webview-on.html

Android WebView文件上传

当我单击按钮时,filechooser在chrome之类的桌面浏览器中运行良好,浏览器打开一个对话框,供我选择要上传的文件.

filechooser works fine in a desktop browser like chrome when I click the button and the browser opens a dialog box where I can choose a file to upload.

当我用手机测试程序时,单击选择文件",对话框没有反应

When I use my cellphone to test the program and I click choose file the Dialog box has no reaction

有人可以帮助我吗?谢谢

Can someone help me? Thanks

推荐答案

请参阅本文档:

https://infeeds.com/d/CODEmgks/20475/upload-image-file-gallery-or-camera-webv

public boolean onShowFileChooser(
     WebView webView, ValueCallback<Uri[]> filePathCallback,
     WebChromeClient.FileChooserParams fileChooserParams){
     if(mUMA != null){
          mUMA.onReceiveValue(null);
     }
     mUMA = filePathCallback;
     Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     if(takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null){
          File photoFile = null;
          try{
               photoFile = createImageFile();
               takePictureIntent.putExtra("PhotoPath", mCM);
          }catch(IOException ex){
               Log.e(TAG, "Image file creation failed", ex);
          }
          if(photoFile != null){
               mCM = "file:" + photoFile.getAbsolutePath();
               takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
          }else{
               takePictureIntent = null;
          }
     }
     Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
     contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
     contentSelectionIntent.setType("image/*");
     Intent[] intentArray;
     if(takePictureIntent != null){
          intentArray = new Intent[]{takePictureIntent};
     }else{
          intentArray = new Intent[0];
     }

     Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
     chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
     chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
     chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
     startActivityForResult(chooserIntent, FCR);
     return true;
}

创建图片文件功能,如上面的代码中所述,我们需要使用它来创建要上传的新临时文件.

Create image file function, as mentioned in the above code we need this to create new temp file to upload.

private File createImageFile() throws IOException{
     @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
     String imageFileName = "img_"+timeStamp+"_";
     File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
     return File.createTempFile(imageFileName,".jpg",storageDir);
}

这篇关于webview,文件输入字段filechooser不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆