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

后端 未结 3 1306
我寻月下人不归
我寻月下人不归 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-07 10:02

    As,suggested by @CommonsWare -

    Camera App do not need to return uri.

    Also,

    You need to tell Camera app where to write image.

    So, i replaced my code with-

     final Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                pictureUri=getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,pictureUri);
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    

    and in onActivityResult -

     case REQUEST_IMAGE_CAPTURE:
    
                if (resultCode==RESULT_OK){
                    String picturePath="";
                    String column_Name= MediaStore.Images.Media.DATA;
                    if (data!=null){
                    if (data.getData()!=null){
                    picturePath=getPathfromUri(column_Name,data.getData());}
    
                    else {
                        picturePath= pictureUri.getPath();
    
                    }
                    }
                    else {
                        picturePath= pictureUri.getPath();
    
                    }}
    

提交回复
热议问题