getExternalFilesDir(Environment.DIRECTORY_PICTURES) 在某些 Android 9 和 10 设备中不起作用

问题描述

以下代码显示camera Intent 和相应的 onActivityResult 代码。它在大多数设备上运行良好,但在某些 Android 9 和 Android 10 设备中,var_Bitmap 为 null,因为 pictureFilePath 为空。这 getExternalFilesDir(Environment.DIRECTORY_PICTURES) 是否适用于所有设备?还是因为其他问题?

 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File imagefile=null;

        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        try {
            imagefile = File.createTempFile("pic",".jpg",storageDir);

        } catch (IOException e) {
            e.printstacktrace();
        }
        pictureFilePath = imagefile.getAbsolutePath();
        Uri photoURI = FileProvider.getUriForFile(this,"com.xyz.xyz.fileprovider",imagefile);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI);
        startActivityForResult(cameraIntent,2);

onActivityResult

 File imgFile = new  File(pictureFilePath);
            if(imgFile.exists()) {
                var_imageview_browse.setimageURI(Uri.fromFile(imgFile));
                var_imageview_browse.setScaleType(ImageView.ScaleType.FIT_XY);
                var_Bitmap = BitmapFactory.decodeFile(pictureFilePath);
                imgFile.delete();

                if (var_Bitmap == null)
                    var_textview_er.setText("An error occurred.");
                else {
                    var_Bitmap = Bitmap.createScaledBitmap(var_Bitmap,INPUT_SIZE,false);

                 
            }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)