Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android/Java WebView文件上载在Android版本10和11中失败_Java_Android_File Upload_Webview - Fatal编程技术网

Android/Java WebView文件上载在Android版本10和11中失败

Android/Java WebView文件上载在Android版本10和11中失败,java,android,file-upload,webview,Java,Android,File Upload,Webview,我有一个android应用程序,其中我有一个网络视图。这个网络视图包含一个上传图片的文件,它的工作方式就像安卓6到9的魔咒一样。对于第10版,如果我使用图库中的图片,它仍然有效,但是如果我试图通过相机直接使用图片,它会告诉我它没有外部存储的权限。我已经在设置中给了它访问权限,因为我还没有实现权限问题。对于版本11,它几乎是相同的,只是我没有得到任何错误。我检查了一些东西,我认为这是因为出于某种原因,“ACTION\u IMAGE\u CAPTURE”的意图返回空值。我错过什么了吗 onShowF

我有一个android应用程序,其中我有一个网络视图。这个网络视图包含一个上传图片的文件,它的工作方式就像安卓6到9的魔咒一样。对于第10版,如果我使用图库中的图片,它仍然有效,但是如果我试图通过相机直接使用图片,它会告诉我它没有外部存储的权限。我已经在设置中给了它访问权限,因为我还没有实现权限问题。对于版本11,它几乎是相同的,只是我没有得到任何错误。我检查了一些东西,我认为这是因为出于某种原因,“ACTION\u IMAGE\u CAPTURE”的意图返回空值。我错过什么了吗

onShowFileChooser

public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
            // Double check that we don't have any existing callbacks
            if (mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePath;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                // Create the File where the photo should go

                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                    Log.d("test", "Test1");

                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Toast.makeText(getApplicationContext(), "\"Unable to create Image File", Toast.LENGTH_SHORT).show();

                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "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, INPUT_FILE_REQUEST_CODE);

            return true;

        }
onActivityResult()

@覆盖
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP){
if(requestCode!=输入_文件_请求_代码| | mFilePathCallback==null){
super.onActivityResult(请求代码、结果代码、数据);
返回;
}
Uri[]results=null;
//检查响应是否良好
if(resultCode==Activity.RESULT\u确定){
if(data==null | | data.getDataString()==null){
//如果没有数据,那么我们可能已经拍了一张照片
if(mCameraPhotoPath!=null){
结果=新Uri[]{Uri.parse(mCameraPhotoPath)};
}
}否则{
字符串dataString=data.getDataString();
if(数据字符串!=null){
结果=新Uri[]{Uri.parse(dataString)};
}
}
}
mFilePathCallback.onReceiveValue(结果);
mFilePathCallback=null;
}else if(Build.VERSION.SDK_INT
    private File createImageFile() throws IOException {
        try {
            // Create an image file name
            String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
            String imageFileName = "JPEG_" + timeStamp + "_";
            File storageDir = Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES);
            File imageFile = File.createTempFile(
                    imageFileName,  /* prefix */
                    ".jpg",         /* suffix */
                    storageDir      /* directory */
            );
            return imageFile;
        } catch (Exception e) {
            Log.d("test", e.getMessage());
            return null;
        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
                super.onActivityResult(requestCode, resultCode, data);
                return;
            }

            Uri[] results = null;

            // Check that the response is a good one
            if (resultCode == Activity.RESULT_OK) {
                if (data == null || data.getDataString() == null) {
                    // If there is not data, then we may have taken a photo
                    if (mCameraPhotoPath != null) {
                        results = new Uri[]{Uri.parse(mCameraPhotoPath)};
                    }
                } else {
                    String dataString = data.getDataString();
                    if (dataString != null) {
                        results = new Uri[]{Uri.parse(dataString)};
                    }
                }
            }

            mFilePathCallback.onReceiveValue(results);
            mFilePathCallback = null;

        } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            if (requestCode != FILECHOOSER_RESULTCODE || mUploadMessage == null) {
                super.onActivityResult(requestCode, resultCode, data);
                return;
            }

            if (requestCode == FILECHOOSER_RESULTCODE) {

                if (null == this.mUploadMessage) {
                    return;

                }

                Uri result = null;

                try {
                    if (resultCode != RESULT_OK) {

                        result = null;

                    } else {

                        // retrieve from the private variable if the intent is null
                        result = data == null ? mCapturedImageURI : data.getData();
                    }
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "activity :" + e,
                            Toast.LENGTH_LONG).show();
                }

                mUploadMessage.onReceiveValue(result);
                mUploadMessage = null;

            }
        }

        return;
    }