当ACTION_IMAGE_CAPTURE意图在横向摄像机方向上返回时,无法在onActivityResult上恢复活动

时间:2014-09-04 20:38:04

标签: android android-intent camera landscape

我在写这个问题之前经常搜索。 我有一个Intent从相机中选择一个图像,其中extra_output存储在Uri中

当图像以纵向捕捉和/或没有自动旋转时,效果非常好。 但是,如果您处于横向和自动旋转状态,则某些模型会给我错误。

我的意图代码:

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
startActivityForResult(camera, REQUEST_CAMERA);

我的onActivityResult片段代码:

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ImageView imageFoto = (ImageView) findViewById(R.id.imageIncidenciaDetail);
    imatgeOriginal = null;

    if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK) {
        //if(imageFile != null)
        imatgeOriginal = BitmapFactory.decodeFile(imageFile.getAbsolutePath());

我实际上有两个不同的错误:

java.lang.RuntimeException: Unable to resume activity     {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}:     java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}:    java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2928)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3865)
at android.app.ActivityThread.access$700(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1346)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null,     request=1, result=-1, data=null} to activity         {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}:             java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3488)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2883)
... 13 more 
Caused by: java.lang.NullPointerException
at com.vicopo.com.lapoblainfo.incidencia_detail.onActivityResult(incidencia_detail.java:145)
at android.app.Activity.dispatchActivityResult(Activity.java:5311)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3484)
... 14 more

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1,   result=-1, data=null} to activity     {com.vicopo.com.lapoblainfo/com.vicopo.com.lapoblainfo.incidencia_detail}:  java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3135)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3178)
at android.app.ActivityThread.access$1100(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
at java.lang.reflect.Method.invokeNative(Native Method)  
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at   com.vicopo.com.lapoblainfo.incidencia_detail.onActivityResult(incidencia_detail.java:145)
at android.app.Activity.dispatchActivityResult(Activity.java:4663)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3131)
... 11 more

Android Manifest活动代码:

<activity
        android:name=".incidencia_detail"
        android:label="@string/title_activity_incidencia_detail"
        android:screenOrientation="portrait"
        android:configChanges="orientation"
        >

我可以执行if和并检查图像是否为空。如果我这样做应用程序没有崩溃,但图像为空。

1 个答案:

答案 0 :(得分:1)

imageFile路径保存在saveInstanceState(Bundle out)的{​​{1}}上,并Activity恢复imageFile,如果onCreate(Bundle savedInstanceState)。您可能需要将savedInstanceState != null存储为imageFile,以便将其保存到String