When i try to get the Uri from a picture taken with the camera i get null

后端 未结 2 695
梦毁少年i
梦毁少年i 2020-12-12 00:18

here is my problem, when i try to get the Uri from the picture that I take whit the camera i get null with the camera on emulator and my device, but only whit the system cam

2条回答
  •  独厮守ぢ
    2020-12-12 00:45

    Android might have killed off (and restarted) your activity before you get into onActivityResult, for instance because you rotated your device while taking the picture. Try to store and restore outputFileUri with the rest of the Activity state...

    protected void onSaveInstanceState(Bundle outState)
    {
        outState.putParcelable("outputFileUri", outputFileUri);
    }
    

    ...

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        if (savedInstanceState != null)
        {
            outputFileUri= savedInstanceState.getParcelable("outputFileUri");
        }
    }
    

提交回复
热议问题