没有应用程序可以执行此操作 - 打开图库/照片时出现问题 Huawei (HMS)
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;
}
}
问题(华为P40 Mate Pro)
点击按钮后显示 - 没有应用程序可以执行此操作。但是这段代码不会崩溃。我正在研究类似的问题,但找不到适合我的正确解决方案。
但是,在华为 P20 Pro 上一切正常。
这可能是什么原因造成的?谢谢
问题出在这条线上
startActivityForResult(Intent.createChooser(chooserIntent, getString(R.string.select_pic)), REQUEST_SELECT_FILE);
我必须修复
startActivityForResult(chooserIntent, REQUEST_SELECT_FILE);
@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);