Android 当我启动摄像头在Redmi 7A上拍照时,应用程序崩溃。也无法在UncaughtException处理程序中捕获崩溃

Android 当我启动摄像头在Redmi 7A上拍照时,应用程序崩溃。也无法在UncaughtException处理程序中捕获崩溃,android,android-studio,android-camera,redmi-device,Android,Android Studio,Android Camera,Redmi Device,当我启动摄像头在Redmi 7A上拍照时,应用程序崩溃。也无法在UncaughtException处理程序中捕获崩溃 拍摄完图像后,它仍停留在同一屏幕上,看起来没有崩溃,但所有数据都已清除 Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File out = getActivity().getExternalFilesDir(null); filename = (System.currentTimeM

当我启动摄像头在Redmi 7A上拍照时,应用程序崩溃。也无法在UncaughtException处理程序中捕获崩溃

拍摄完图像后,它仍停留在同一屏幕上,看起来没有崩溃,但所有数据都已清除

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File out = getActivity().getExternalFilesDir(null);
        filename = (System.currentTimeMillis() + ".jpg");
        out = new File(out, filename);
        if (Build.VERSION_CODES.N <= Build.VERSION.SDK_INT) {
            picUri = FileProvider.getUriForFile(getContext(), getContext().getApplicationContext().getPackageName() + ".provider", out);
            i.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
        } else {
            i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
        }
        getActivity().startActivityForResult(i, ConstantsUtils.CAMERA_REQUEST_CODE);
并在清单中添加了必需的功能

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="true" />


很抱歉,我没有找到此错误的任何日志,如果您需要任何帮助,我们将不胜感激。

您必须使用FileProvider。FileProvider是ContentProvider的一个特殊子类,它允许通过content URI而不是file://URI在应用程序之间共享文件。 在res/XML文件夹中创建一个XML文件(provider_path.XML),并定义它的清单文件

在provider_path.xml文件中编写以下代码。
如果您在catch块中添加了try catch write printStackTrace(),日志应该在那里。
<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="true" />