ACTION_IMAGE_CAPTURE returns imagefile as Extra instead of Data

僤鯓⒐⒋嵵緔 提交于 2019-12-02 06:52:57

Usually I can simply call getData() on the intent I receive in onActivityResult and get the content uri for the MediaProvider.

Your code will fail on many of them, including all recent Nexus devices. ACTION_IMAGE_CAPTURE is not supposed to return a Uri. Quoting the documentation:

If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

Since you are not including EXTRA_OUTPUT, you will get a data extra (getData().getExtra("data")) with a thumbnail image.

the intent I get in onActivityResult has no data, but instead, it has a parcellable extra

Given your ACTION_IMAGE_CAPTURE request, that is what you are supposed to get.

If you want a full-size image, include EXTRA_OUTPUT, perhaps pointing to a FileProvider in your app, such as I demonstrate in this sample app. Then, you know the Uri where the photo should go, because you specified that Uri.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!