Android Open album, select a picture and return
An open album
private static final int album_ok = 0;
Intent albumintent = new Intent (Intent.action_pick, null); Albumintent.setdataandtype ( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); Startactivityforresult (Albumintent, ALBUM_OK);
Two display picture and picture information
Open the album using the
Startactivityforresult (Albumintent, ALBUM_OK);
Therefore, a onactivityresult (int requestcode, int resultcode, Intent data) is required to get the result returned:
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (Album_ok = = Requestcode) {Toast.maketex T (this, "OK", Toast.length_short). Show (); Bitmap Bitmap; LOG.E ("Mainactivity", "Onactivityresult"); Contentresolver CR = This.getcontentresolver (); Uri uri = Data.getdata (); try {bitmap = Bitmapfactory.decodestream (Cr.openinputstream (URI)); LOG.E ("Mainactivity", "Onactivityresult" + data.getdata (). toString ());// Here with LOG.E, only to see the red log convenient imageview.setimagebitmap (bitmap); Readexifinfo (Getimagepath (URI));//This is the EXIF} catch that is used to read the picture ( FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();}}}
Getimagepath (Uri) The resource path used to get the picture:
Private String Getimagepath (Uri uri) {if (null = = URI) {log.e ("Getimagepath", "uri return null"); return null;} LOG.E ("Getimagepath", uri.tostring ()); String path = null;final string scheme = Uri.getscheme (), if (null = = Scheme) {path = Uri.getpath ();} else if (Contentresol Ver. Scheme_file.equals (Scheme)) {path = Uri.getpath ();} else if (ContentResolver.SCHEME_CONTENT.equals (scheme)) {string[] proj = {MediaStore.Images.Media.DATA}; cursor cursor = getcontentresolver (). Query (URI, proj, NULL, null,null), int nphotocolumn = Cursor.getcolumnindexorthrow ( MediaStore.Images.Media.DATA); if (null! = cursor) {Cursor.movetofirst ();p ath = cursor.getstring (nphotocolumn);} Cursor.close ();} return path;}
Readexifinfo function (for reference only, here with log to display EXIF):
private void Readexifinfo (String path) throws IOException {exifinterface exif = new Exifinterface (path); String ISO = exif.getattribute (exifinterface.tag_iso); String make = Exif.getattribute (Exifinterface.tag_make); String model = Exif.getattribute (Exifinterface.tag_model); String flash = Exif.getattribute (Exifinterface.tag_flash); String time = Exif.getattribute (exifinterface.tag_datetime); String wb = Exif.getattribute (exifinterface.tag_white_balance); String aperture = Exif.getattribute (exifinterface.tag_aperture); String width = exif.getattribute (exifinterface.tag_image_width); String height = exif.getattribute (exifinterface.tag_image_length); String Focal_len = Exif.getattribute (exifinterface.tag_focal_length); String exposure_time = Exif.getattribute (exifinterface.tag_exposure_time); String msg = "Times:" + time + "\ n Model:" + model + "\ n Manufacturer:" + make + "\ n Light sense:" + ISO + "\ n Exposure:" + exposure_time + "\ n aperture:" + aperture + "\ n Flash:" + flash + "\ n focal length:" + focal_len+ "\ n Height:" + height + "\ n Width:" + wiDTH + "\ n White balance:" + wb; LOG.E ("Readexifinfo", msg); Alertdialog.builder builder = new Builder (mainactivity.this), Builder.settitle ("Exif"); Builder.setmessage (msg); Builder.create (). Show ();
If eclipse can have a vs so cool in the sink, it's OK
Android Open album, select a picture and return