如何解决处理媒体存储故障
所以基本上我正在将我的应用程序迁移到范围存储。 我在 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;
}
迄今为止尝试过的解决方案:
- 将
Environment.getExternalStoragePublicDirectory
更改为context.getExternalFilesDir
(无效)。 - 将
File(mediaCapturePath).getParentFile();
更改为File(context.context.getCacheDir(),getmediaCapturePath).getParentFile();
(无效)。 - 尝试调试,但未从相机应用收到回调。
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。