java - 没有应用程序可以执行此操作 - 打开画廊/照片华为 (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);
推荐阅读
- office-js - 以编程方式打开“拆分”窗口模式
- java - Java Program. Need to simplified public boolean equals (object B){ is to long. I do not how to reduce the coding in that part of my program
- python - Python - 旧输入仍在输入缓冲区中?
- javascript - 将工作表添加到 Jquery 数据表的 excel 输出中
- r - 仅使用 2 个向量的部分分量的操作
- java - 为什么没有文件被退回?
- scala - scala中的伴侣对象
- c# - 您如何使用 ProtectedBrowserStorage 和 BlazorServer AspNet 身份验证进行基于 Cookie 的登录?
- android-studio - 不支持此模型:输入张量 0 没有名称
- javascript - 单击按钮时尝试更改游戏动作但不起作用