ACTION_IMAGE_CAPTURE onActivityResult has empty intent with empty data

前端 未结 1 1102
你的背包
你的背包 2020-12-12 08:39

After reading this documentation https://developer.android.com/training/camera/photobasics I want to take a photo and to store the uri of the photo into a given variable. Th

相关标签:
1条回答
  • 2020-12-12 09:04

    You already have photoURI which you send with MediaStore.EXTRA_OUTPUT so You can simply use it . Save photoURI as globally and directly use it . See if RESULT_OK is emitted then it means picture was clicked and it will be saved at the EXTRA_OUTPUT location.

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if( requestCode == Constants.REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
            // USe photoURi here
        }
    }
    

    You can not expect some custom key which is Constants.INTENT_EXTRA_VARNAME will be return with System camera Intent. I do not have any knowledge of such thing.
    If you specified MediaStore.EXTRA_OUTPUT the image taken will be written to that path, and no data will given to onActivityResult so you need to persist the file path.

    PS : You can save it globally and also make sure you should persist it during onSaveInstanceState().

    0 讨论(0)
提交回复
热议问题