Android4.4 the path returned from the gallery select picture is not the correct workaround

Source: Internet
Author: User

Selecting images from the gallery is a very common feature in our development, such as uploading avatars and uploading albums. Android4.4 Previous version Open the gallery Select picture can be this:

Intent Intent = new Intent (intent.action_get_content, null); Intent.settype ("image/*"); Activity.startactivityforresult (Intent, Start_album_code);

Or:

Intent Intent = new Intent (Intent.action_pick, null); Intent.setdataandtype (MediaStore.Images.Media.EXTERNAL_CONTENT _uri, "image/*"); Activity.startactivityforresult (Intent, Start_album_code);

Then we rewrite Onactivityresult (), and in the returned data we can get the path of the image (how to get path can be searched online).
But in the Android4.4 test but there is a problem, get the correct path, get the path is this:/document/image%3a29817, and our normal path:/mnt/sdcard/dcim/100media/ Imag0021.jpg, not the same.
The method that works on Android4.4 should be this way (also compatible with the previous version of 4.4):

Intent Intent = new Intent (Intent.action_pick,android.provider.mediastore.images.media.external_content_uri); Intent.setdataandtype (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); Activity.startactivityforresult ( Intent, Start_album_code);

This will enable you to obtain the correct path.


Ps:
Another solution (feeling written is cumbersome, not verified, for reference only): http://blog.csdn.net/tempersitu/article/details/20557383


QQ Exchange Group: 6399844

Android4.4 the path returned from the gallery select picture is not the correct workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.