Public interface photocallback { voidOnsuccess (String PicturePath);//Take photos successfully voidOnFailure ();//Take photos failed}/** * Get Picture Path * * @param context * @param data * @param Callback * @return * * Public Static void Getphotourlbyalbum(context context, Intent data, Photocallback callback) {if(Data = =NULL) {callback.onfailure ();return; }FinalUri selectedimage = Data.getdata ();if(SelectedImage = =NULL) {callback.onfailure ();return; } String PicturePath ="";//About Android4.4 's picture path gets, if the format of the URI comes back in two ways if(Build.VERSION.SDK_INT >= +&& Documentscontract.isdocumenturi (context, SelectedImage)) {String Wholeid = documentscontract.ge Tdocumentid (SelectedImage); String id = wholeid.split (":")[1]; string[] column = {MediaStore.Images.Media.DATA}; String sel = mediastore.images.media._id +"=?"; cursor cursor = context.getcontentresolver (). Query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, SEL,NewString[] {ID},NULL);if(Cursor.movetonext ()) {intColumnIndex = Cursor.getcolumnindex (column[0]); PicturePath = cursor.getstring (columnindex); Callback.onsuccess (PicturePath);//Get Picture path} cursor.close (); }Else{string[] projection = {MediaStore.Images.Media.DATA}; cursor cursor = context.getcontentresolver (). Query (selectedimage, projection,NULL,NULL,NULL);if(Cursor.movetonext ()) {intColumn_index = Cursor.getcolumnindex (MediaStore.Images.Media.DATA); PicturePath = cursor.getstring (Column_index); Callback.onsuccess (PicturePath);//Get Picture path} cursor.close (); } }
The returned data is processed in the Onactivityresult.
And be sure to make a decision in the logic of opening the album.
intent Intent = new Intent () ; Intent.settype ( "image/*" ) ;//Choose from all pictures //Use different action if (Build _int <19 ) {intent.setaction (Intent _get_content) ; }else {intent.setaction (Intent _open_document) ; } (Activity) context) .startactivityforresult (Intent, constants< Span class= "Hljs-preprocessor". REQUEST _code_headpic_pick_photo) ;
Reference:
http://blog.csdn.net/huangyanan1989/article/details/17263203
http://blog.csdn.net/eastman520/article/details/17756817
Android4.4 Open System album return NULL issue