首页 > 解决方案 > 没有应用程序可以执行此操作 - 打开画廊/照片华为 (HMS) 出现问题

问题描述

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
        time = System.currentTimeMillis();
        if (checkStorageperm()) {
            if (checkCameraperm()) {
                if (uploadMessage != null) {
                    uploadMessage.onReceiveValue(null);
                    uploadMessage = null;
                }

                uploadMessage = filePathCallback;

                Intent pickIntent = fileChooserParams.createIntent();

                String[] mimetypes = {"image/*", "application/pdf"};
                pickIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
                pickIntent.setAction(Intent.ACTION_GET_CONTENT);

                Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                if (takePhotoIntent.resolveActivity(getContext().getPackageManager()) != null) {
                    // Create the File where the photo should go
                    File photoFile = null;
                    try {
                        photoFile = RegistrationFragment.createImageFile();
                        takePhotoIntent.putExtra("PhotoPath", mCameraPhotoPath);
                    } catch (IOException ex) { }

                    // Continue only if the File was successfully created
                    if (photoFile != null) {
                        mCameraPhotoPath = photoFile.getAbsolutePath();
                        takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                Uri.fromFile(photoFile));
                    } else {
                        takePhotoIntent = null;
                    }
                }
                
                String pickTitle = getString(R.string.select_or_take_new_pic);
                Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
                chooserIntent.putExtra
                        (
                                Intent.EXTRA_INITIAL_INTENTS,
                                new Intent[]{takePhotoIntent}
                        );

                try {
                    startActivityForResult(Intent.createChooser(chooserIntent, getString(R.string.select_pic)), REQUEST_SELECT_FILE);
                } catch (ActivityNotFoundException e) {
                    uploadMessage = null;
                    Toast.makeText(App.screen.getApplicationContext(), getString(R.string.cannot_open_file_chhoser), Toast.LENGTH_LONG).show();
                    return false;
                }
                return true;
            } else {
                checkPerm();
                return false;
            }
        } else {
            checkPerm();
            return false;
        }
    }

问题(华为 P40 Mate Pro)

单击按钮后显示 - 没有应用程序可以执行此操作。但是这段代码不会崩溃。我正在研究一个类似的问题,但我没有找到适合我的正确解决方案。

但是,在华为 P20 Pro 上一切正常。

这可能是什么原因造成的?谢谢。

标签: javaandroidhuawei-mobile-services

解决方案


所以问题就在这条线上

startActivityForResult(Intent.createChooser(chooserIntent, getString(R.string.select_pic)), REQUEST_SELECT_FILE);

我必须解决

startActivityForResult(chooserIntent, REQUEST_SELECT_FILE);

推荐阅读