Android 11:图像捕获后,相机意图因方向改变而崩溃 [英] Android 11 : Camera Intent Crashes on Orientation Change After Image Capture
问题描述
我正在使用相机意图捕获图像(纵向+横向),并将其显示在Fragment的图像视图中.
I am capturing an image (Portrait + Landscape) using camera intent and showing it in an image view in Fragment.
我已遵循以下链接中的所有说明
I had followed all instructions from the below link,
https://developer.android.com/training/camera/photobasics
该代码在Android 10之前的设备上都可以正常运行,但在Android 11设备上(尤其是三星手机)上无法正常工作.
The Code is working fine on devices till Android 10, but not working on Android 11 devices (especially Samsung Phones).
我已经尝试了所有关于Stack Overflow的解决方案.
I had tried all possible solutions on Stack Overflow.
该应用程序仅在以下情况下崩溃
The application crashes in the below scenario only,
复制步骤,
- 用户启动Camera捕获图像
- 旋转手机以横向模式拍摄图像.
- 用户成功捕获图像,然后单击对勾或确定".如果以人像"模式捕获图像,则应用程序不会崩溃.
我遇到以下错误,(在Crashlytics上报道)
I am getting the below error, (reported on Crashlytics)
Caused by java.lang.NullPointerException
at java.io.File.<init>(File.java:283)
at com.kyc.views.PDFragment.onActivityResult(PDFragment.java:442)
at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:170)
Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.kyc/com.kyc.main.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65660, result=-1, data=null} to activity {com.kyc/com.kyc.main.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4852)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4885)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
推荐答案
处理配置更改"通过在清单中的活动中添加 android:configChanges ="orientation"
.问题是当屏幕旋转回纵向时,回到应用程序后旋转.有些电话可以处理,有些则不能.
Handle "config changes" by adding android:configChanges="orientation"
in your activity in Manifest. Problem is rotation after you back to your app when screen is rotating back to portrait. Some phones can handle this, some not.
这篇关于Android 11:图像捕获后,相机意图因方向改变而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!