android - 使用相机拍照后,黑屏几秒钟(2或3秒)
问题描述
使用相机拍照后,黑屏会出现几秒钟(2 或 3 秒),然后才会显示 UI 布局。我使用异步任务来获取保存的文件,如下所示。该功能运行良好。但是由于几秒钟的黑屏,用户体验很差。
相机意图代码
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagefile=null;
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
try {
imagefile = File.createTempFile("zicu", ".jpg", storageDir);
} catch (IOException e) {
e.printStackTrace();
}
pictureFilePath = imagefile.getAbsolutePath();
Uri photoURI = FileProvider.getUriForFile(this,
"com.mmxyz.zicu.fileprovider",
imagefile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(cameraIntent, 2);
onActivityResult
代码
if ((requestCode == 2))
{
Feedcamera fc= new Feedcamera();
fc.execute("0");
var_textview_error.setText("Processing....");
}
异步任务
private class Feedcamera extends AsyncTask<String, Void, File> {
protected File doInBackground(String... urls) {
File imgFile = new File(pictureFilePath);
return imgFile;
}
protected void onPostExecute(File imgFile) {
if(imgFile.exists()) {
var_imageview_browse.setImageURI(Uri.fromFile(imgFile));
}
解决方案
推荐阅读
- asp.net - ASP.NET RegularExpressionValidator 错误触发器
- facebook - 从特定地理位置(经纬度)获取 Facebook 用户帖子/状态更新
- linux - 如何使用 docker 映像构建应用程序?
- jquery - jquery 将 href 转为 xlink:href
- asp.net - 命名api路由的最佳实践是什么?
- macos - 使用英特尔编译器创建通用二进制文件
- html - HTML/CSS 背景与其他屏幕尺寸不匹配
- django - django rest 框架“ModuleNotFoundError:没有名为‘路由器’的模块”
- ubuntu - 报告为专有的开源 .deb 包
- typescript - 函数类型 - TypeScript