onActivityResult returning Intent data.getData(); always Null Only in Marshmallow and Lollipop

后端 未结 3 1322
我寻月下人不归
我寻月下人不归 2021-01-07 09:39

Read My Whole Code. It is working perfectly on every Phone except Marshmallow and Lollipop. In Marshmallow and Lollipop p

3条回答
  •  庸人自扰
    2021-01-07 10:11

    It is working perfectly on every Phone except Marshmallow and Lollipop

    No, it is not. It will fail on lots of Android versions, when the user chooses a well-written camera app to handle your ACTION_IMAGE_CAPTURE request.

    Your problem lies here:

                if (data.getData()!=null){
                picturePath=getPath(column_Name,data.getData());}
                else {
                    //My app Crashes here because in Marshmallow data.getData() is always null.
                }
    

    There are at least two flaws here.

    The big one is assuming that you get a Uri back from ACTION_IMAGE_CAPTURE. That is not documented, and camera apps do not need to return a Uri. In particular, in your structure, you will only get a thumbnail back, via getExtra("data"). If you want a full-size image, use EXTRA_OUTPUT on your Intent, in which case you know where the image is being stored — it is wherever you are indicating in EXTRA_OUTPUT.

    The other one is that you assume that the Uri that you get back is from the MediaStore or otherwise has a MediaStore.Video.Media.DATA column. Not only do camera apps not have to return a Uri, but there is no requirement that the Uri is from the MediaStore or have such a column.

提交回复
热议问题