[Android] get pictures from gallery

Source: Internet
Author: User

The effect is to click the button, open the System library application, you can choose a picture inside the show out

Set an implicit intent

Get Intent object, come out with new

Call the setaction () method of the Intent Object , set the action, parameter:intent.action_pick

Call the SetType () method of the Intent Object , set the type, parameter:"image/*" can also get video

Call the Startactivityforresult () method to turn on the return value of the

View the system's gallery Source code can know, returned a Intent object, inside the implicit pass data, additional data

overriding method Onactivityresult () method

Gets the Uri pathto the picture, the getData () method of the Intent Object

Image thumbnail Bitmap object, calling the Intent object's Getparcelableextra ("data");

Call the Setimageuri () method of the ImageView object to display the picture directly

    //Select Picture     Public voidselectimg (View v) {Intent Intent=NewIntent ();        Intent.setaction (Intent.action_pick); Intent.settype ("Image/*"); Startactivityforresult (Intent,0); }    //Response Callback@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        if(data!=NULL) {URI Uri=Data.getdata ();        Iv_img.setimageuri (URI); }            }

[Android] get pictures from gallery

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.