Android data.getData() returns null from CameraActivity for some phones

前端 未结 2 1115
时光取名叫无心
时光取名叫无心 2020-12-20 21:53

I have a fatal error occurring in my onActivityResult coming back from a camera activity. What has me scratching my head is that the error is only happening on a handful of

相关标签:
2条回答
  • 2020-12-20 22:11
    Uri imageUri = data.getData(); //The trouble is here
    

    There is no requirement for a camera app to return a Uri pointing to the photo, as that is not part of the ACTION_IMAGE_CAPTURE Intent protocol. Either:

    • Supply EXTRA_OUTPUT in your ACTION_IMAGE_CAPTURE Intent, in which case you know where the image should be stored, and do not need to rely upon getData(), or

    • Use the data extra in the response Intent, which will be a Bitmap of a thumbnail of the image

    Your next bug is here:

    String realPath = Image.getPath(this, imageUri);
    

    There is no requirement that the image be stored as a file that you can access, unless you provide a path to that location via EXTRA_OUTPUT.

    0 讨论(0)
  • 2020-12-20 22:17

    if(resultCode == RESULT_OK){

                    Bitmap bitmap = (Bitmap) imageReturnedIntent.getExtras().get("data");
                    imageView.setImageBitmap(bitmap);
                }
    
    0 讨论(0)
提交回复
热议问题