首页 > 解决方案 > (Webview) Android 捕获的图像保存不工作某些版本

问题描述

我正在做一个 webview 应用程序。我的网站上有一个表格,需要通过表格上传图片。我通过 file_input 选择相机,拍照,但是当我返回时,我看到图像没有保存在文件输入中。不工作的版本(我不知道全部):Android 10,Android 7。运行版本:Android 9,Android 5。我只是后端 Web 开发人员,我不太擅长移动编程。最后; 下面的代码返回 null。

takePictureIntent.resolveActivity(activity_ismi.this.getPackageManager()) // returns null

//For Android 5.0+
        @SuppressLint("QueryPermissionsNeeded")
        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(customActivity.this.getPackageManager()) == null){
                File photoFile = null;
                try{
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCM);
                }catch(IOException ex){
                    Log.e(TAG, "failed to create image", ex);
                }
            }
            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("*/*");
            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, "Please select");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
            startActivityForResult(chooserIntent, FCR);
            return true;
        }

我从相机捕获图像,但输入文件如下:在此处输入图像描述

标签: javaandroidwebview

解决方案


推荐阅读