在写问题之前,我进行了很多搜索。
我打算从具有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和检查图像是否不为空。如果我这样做,该应用程序不会崩溃,但是图像为空。

最佳答案

imageFile路径保存在saveInstanceState(Bundle out)Activity上,如果imageFile,则将onCreate(Bundle savedInstanceState)还原到savedInstanceState != null。您可能需要将imageFile存储为String才能保存到Bundle

关于android - 当ACTION_IMAGE_CAPTURE意向返回横向相机方向时,无法在onActivityResult上恢复 Activity ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25674602/

10-10 18:34