Android Get Pictures

Source: Internet
Author: User

The first is the acquisition of photo albums:

Private FinalString Image_type = "image/*";Private Final intImage_code = 0;//the image_code here are arbitrarily defined by themselves.//use intent to invoke the system-provided photo album feature and use Startactivityforresult to get a picture of the user's choiceIntent getalbum=NewIntent (intent.action_get_content); Getalbum.settype (Image_type); Startactivityforresult (Getalbum, IMAGE_CODE) ; //rewrite Onactivityresult to get the information you need@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {    if(ResultCode! = RESULT_OK) {//The RESULT_OK here is a constant system customizationlog.e (TAG,"Activityresult ResultCode Error"); return; } Bitmap BM=NULL; //the data provided by the external program Access ContentProvider can be accessed via the Contentresolver interfaceContentresolver Resolver=Getcontentresolver (); //This is the one you want to use to determine if the activity you're receiving    if(Requestcode = =Image_code) {        Try{Uri Originaluri= Data.getdata ();//get the URI of the pictureBM= MediaStore.Images.Media.getBitmap (resolver, Originaluri);//appear to bitmap pictureshere begins the second part, gets the path of the picture: string[] proj={MediaStore.Images.Media.DATA}; //It seems to be an interface for Android multimedia database, specifically look at the Android documentcursor Cursor= Managedquery (Originaluri, Proj,NULL,NULL,NULL); //as I understand it, this is the index value of the image that the user chooses.            intColumn_index =Cursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA); //move the cursor to the beginning, this is important, careless can easily cause a cross-borderCursor.movetofirst (); //finally get the picture path according to the index valueString Path=cursor.getstring (Column_index); }Catch(IOException e) {log.e (tag,e.tostring ()); }    } } 

From the online forum it appears that the method of alternate

Android Get Pictures

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.