首页 > 解决方案 > 使用相机拍照后,黑屏几秒钟(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));
            }

标签: androidandroid-cameraandroid-camera-intent

解决方案


推荐阅读