没有应用程序可以执行此操作-打开画廊/照片华为(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上,一切都很好。

是什么原因造成的?谢谢

所以这一行出现了问题

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

我必须修复

startActivityForResult(chooserIntent, REQUEST_SELECT_FILE);

最新更新