处理媒体存储故障

问题描述

所以基本上我正在将我的应用程序迁移到范围存储。 我在 android 版本 10 中捕获图像时遇到问题。

(适用于 android 版本 11)。

系统日志

E/CAM_FatalErrorHandler: Handling Media Storage Failure:
    java.lang.Exception
        at d.b.a.Rb.Ge(SourceFile:1)
        at d.b.a.cf.onError(SourceFile:1)
        at d.b.a.cf.av(SourceFile:12)
        at d.b.a.De.onClick(SourceFile:1)
        at android.view.View.performClick(View.java:7125)
        at android.view.View.performClickInternal(View.java:7102)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27340)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7397)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
2021-04-22 19:43:08.303 3031-3031/? E/CAM_CameraUtil: Show Fatal error dialog

相机意图方法

private static Intent getLaunchCameraIntent(Context context,String applicationId,LaunchCameraCallback callback)
            throws IOException {
        File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        String mediaCapturePath = externalStoragePublicDirectory + File.separator + "Camera" + File.separator + "dd-" + System
                .currentTimeMillis() + ".jpg";

        // make sure the directory we plan to store the recording in exists
        File directory = new File(mediaCapturePath).getParentFile();
        if (directory == null || (!directory.exists() && !directory.mkdirs())) {
            try {
                throw new IOException("Path to file Could not be created: " + mediaCapturePath);
            } catch (IOException e) {
                Log.e(e);
                throw e;
            }
        }

        Uri fileUri;
        try {
            fileUri = FileProvider.getUriForFile(context,applicationId + ".provider",new File(mediaCapturePath));
        } catch (IllegalArgumentException e) {
            Log.e("Cannot access the file planned to store the new media",e);
            throw new IOException("Cannot access the file planned to store the new media");
        } catch (NullPointerException e) {
            Log.e("Cannot access the file planned to store the new media - " +
                    "FileProvider.getUriForFile cannot find a valid provider for the authority: " + applicationId + ".provider",e);
            throw new IOException("Cannot access the file planned to store the new media");
        }

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,fileUri);

        if (callback != null) {
            callback.onMediaCapturePathReady(mediaCapturePath);
        }
        return intent;
    }

迄今为止尝试过的解决方案:

  1. Environment.getExternalStoragePublicDirectory 更改为 context.getExternalFilesDir(无效)。
  2. File(mediaCapturePath).getParentFile(); 更改为 File(context.context.getCacheDir(),getmediaCapturePath).getParentFile();(无效)。
  3. 尝试调试,但未从相机应用收到回调。

提前致谢。

解决方法

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

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

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