相机正在打开,但一段时间后它在android等Redmi 7等设备上的单击图像确定按钮上崩溃了

问题描述

我在清单中给予了所有许可。一切正常,但是在单击“确定”按钮拍照后崩溃了。请帮我任何解决方案 此消息显示

    E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
    E/Perf: Fail to get file list com.app.mytestapp
        getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    W/s.mytestapp: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist,reflection,allowed)
    W/s.mytestapp: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist,allowed)
    W/s.mytestapp: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (greylist,allowed)
        Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontvariationAxis;)Z (greylist,allowed)
        Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontvariationAxis;II)Z (greylist,allowed)
        Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (greylist,allowed)
        Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (greylist,allowed)
        Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (greylist,allowed)

使用此代码打开相机

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + StrFolderName + "/",filename + ".jpg"));
        intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
        startActivityForResult(intent,0);



    protected void onActivityResult(int requestCode,int resultCode,Intent data)
    {

        if (resultCode == RESULT_OK) {

            FileProcessing obj = new FileProcessing(FinalActivty.this);

            File f = new File(uri.getPath());
            Double capturedSize= Double.valueOf((float) f.length() / (1024));
            String Originalsize = String.format("%.5f",capturedSize);
            Double actualPhoto = Double.parseDouble(Originalsize);

        }

    }

解决方法

只需在清单应用程序标签属性中添加以下行即可。

android:requestLegacyExternalStorage="true"

但这是一个临时解决方案。来自 android r 的requestLegacyExternalStorage将被弃用。 有关更多详细信息,您可以参考此link

OR

只需替换您的文件路径,即可尝试以下代码

Uri uri = Uri.fromFile(new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURE) + "/" + StrFolderName + "/",filename + ".jpg"));