NoName222
NoName222

Reputation: 51

No apps can perform this action - problem opening gallery/ photo Huawei (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;
        }
    }

The Problem(Huawei P40 Mate Pro)

After clicking on the button to show - No apps can perform this action. But this code doesn't crash. Im looking at on a similar problem, but I don't find the correct solution for me.

However, on Huawei P20 Pro everything's working fine.

What may be causing this? Thanks.

Upvotes: 0

Views: 365

Answers (1)

NoName222
NoName222

Reputation: 51

So problem was on this line

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

I must fix on

startActivityForResult(chooserIntent, REQUEST_SELECT_FILE);

Upvotes: 1

Related Questions