qq_27204139
qq_27204139
2016-06-01 13:18
采纳率: 100%
浏览 7.0k
已采纳

安卓app内嵌h5图片上传不触发change事件

我在h5页面加入一个,然后把h5内嵌到app中,ios上传是成功的,完全可以调出来相机相册。,安卓的app怎样都不触发change事件,也不会打开相机相册。求助,有没有遇到过类似情况的,求大神帮忙啊。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • d7142947
    MeDC 2016-06-02 02:55
    已采纳

    需要WebView添加支持

       mWebView.setWebChromeClient(new WebChromeClient() {
                @Override
                public boolean onShowFileChooser(WebView webView,
                                                 ValueCallback<Uri[]> filePathCallback,
                                                 FileChooserParams fileChooserParams) {
                    mUploadCallbackAboveL = filePathCallback;
                    take();
                    return true;
                }
    
    
                public void openFileChooser(ValueCallback<Uri> uploadMsg) {
                    mUploadMessage = uploadMsg;
                    take();
                }
    
                public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                    mUploadMessage = uploadMsg;
                    take();
                }
    
                public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
                    mUploadMessage = uploadMsg;
                    take();
                }
    }
    
    
    //=======
    private void take() {
            File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "拉帮结伙");
            if (!imageStorageDir.exists()) {
                imageStorageDir.mkdirs();
            }
            File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
            imageUri = Uri.fromFile(file);
    
            final List<Intent> cameraIntents = new ArrayList<Intent>();
    
             Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    //        Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            Intent chooserIntent = Intent.createChooser(i, "选择文件");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
            MainWebViewActivity.this.startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
        }
    
    点赞 评论
  • sheng582910111
    sheng582910111 2016-06-02 03:41

    这个需要使用js对象调用本地方法,安卓使用h5直接调用是不行的

    点赞 评论

相关推荐