Importjava.io.FileNotFoundException;ImportAndroid.content.ContentResolver;Importandroid.content.Intent;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.ImageView;ImportCOM.MAIKEFENGCHAO.DAIXU.R; Public classWritearticle_competerelayactivityextendsbaseactivity {PrivateImageView im_upload_img; @Override Public voidInitview (Bundle savedinstancestate) {Setcontentview (r.layout.view_write_competerelay); Im_upload_img=(ImageView) Findviewbyid (R.ID.WRITE_COMPETERELAY_COVER_IV); } @Overrideprotected voidSetlistener () {Im_upload_img.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Intent Intent=NewIntent (); /*Turn on pictures screen type set to Image*/Intent.settype ("Image/*"); /*use intent.action_get_content this ACTION*/intent.setaction (intent.action_get_content); /*return to this screen after obtaining a photo*/Startactivityforresult (Intent,1); } }); } @Overrideprotected voidprocesslogic (Bundle saveinstancestate) {}//get local pictures@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { if(ResultCode = =RESULT_OK) {URI Uri=Data.getdata (); LOG.E ("uri", uri.tostring ()); Contentresolver CR= This. Getcontentresolver (); Try{Bitmap Bitmap=Bitmapfactory.decodestream (Cr.openinputstream (URI)); ImageView ImageView=(ImageView) Findviewbyid (R.ID.WRITE_COMPETERELAY_COVER_IV); /*set the bitmap to ImageView*/Imageview.setimagebitmap (bitmap); } Catch(FileNotFoundException e) {LOG.E ("Exception", E.getmessage (), E); } } Super. Onactivityresult (Requestcode, ResultCode, data); }}
Android gets local pictures and displays pictures