How Android browses and selects images, audio, and videos

Source: Internet
Author: User
In the past few days, I have been studying and developing images for Android to browse audio and video. This is the first Android system (Java won't) having encountered many problems, it took me several days to browse and select images, audios, and videos, so that I could help my colleagues and prevent myself from forgetting. <1> select a button. of Code // Select the image button and click the event public void click_xuanqutupian (View Source) {intent = new intent ();/* enable pictures to set the image type to image */intent. settype ("image/*"); // intent. settype ("audio/*"); // select audio // intent. settype ("Video/*"); // select the video (MP4 3GP is the video format supported by Android) // intent. settype ("Video/*; image/*"); // select both video and image/* use intent. action_get_content this action */intent. setaction (intent. action_get_content);/* returns the current screen after obtaining the photo */startactivityforresult (intent, 1);} <2> obtains the position to be processed after the selected item @ overrideprotected void onactivityresult (INT requestcode, int resultcode, intent data) {// select the image return value if (requestcode = 1) {// If (resultcode = result_ OK) {URI uri = data. getdata (); cursor = getcontentresolver (). query (Uri, null, null); cursor. movetofirst (); // string imgno = cursor. getstring (0); // The image number imgpath = cursor. getstring (1); // image file path string imgsize = cursor. getstring (2); // image size string imgname = cursor. getstring (3); // image file name filename = imgname; filesize = imgsize; // log. E ("Uri", Uri. tostring (); contentresolver Cr = This. getcontentresolver (); try {Bitmap bitmap = bitmapfactory. decodestream (Cr. openinputstream (URI); imageview = (imageview) findviewbyid (R. id. imview);/* Set bitmap to imageview */imageview. setimagebitmap (Bitmap);} catch (filenotfoundexception e) {// log. E ("exception", E. getmessage (), e) ;}}// response value of the image if (requestcode = 2) {If (resultcode = result_ OK) {// imgpath = data. getstringextra ("filepath"); filename = data. getstringextra ("FILENAME"); filesize = data. getstringextra ("filesize"); // read the file obtained from the photo. Try {Bitmap bitmap = This. getloacalbitmap (imgpath); imageview = (imageview) findviewbyid (R. id. imview); imageview. setimagebitmap (Bitmap);} catch (exception e) {// todo: handle exception} //} super. onactivityresult (requestcode, resultcode, data );}

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.