当我启动相机在Redmi 7A上拍照时,应用程序崩溃.无法在UncaughtException处理程序中捕捉到崩溃



当我启动相机在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);

在清单中也使用了largeHeap以获得足够的内存

android:largeHeap="true"

并在清单中添加了所需的功能

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

很抱歉,我没有找到这个错误的任何日志,如果有任何帮助,将不胜感激

您必须使用FileProvider.FileProvider是ContentProvider的一个特殊子类,它允许通过内容URI而不是file://URI在应用程序之间共享文件。在res/XML文件夹中创建一个XML文件(provider_path.XML(,并将其定义为Manifest文件<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>

在providerpath.xml文件中编写以下代码。<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="https://schemas.android.com/apk/res/android"> <external-path name="external_files" path="."/> </paths>

最新更新