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

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

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

  • 写回答

2条回答 默认 最新

  • 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);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?