android - Upload Image from inbuilt Gallery -


as don't have sd card. want upload image server selecting image built -in gallery.

can me on how place image in in-built gallery can select there.

any appricated.

you can go inbuilt gallery following code:

button btnbrowse = (button)findviewbyid(r.id.btn_browse);     btnbrowse.setonclicklistener(new view.onclicklistener() {  @override public void onclick(view v) { intent intent = new intent();             intent.settype("image/*");             intent.setaction(intent.action_get_content);             startactivityforresult(intent.createchooser(intent,               "select picture"), select_picture);  } }); 

now onactivityresult should this.

public void onactivityresult(int requestcode, int resultcode, intent data) {  if (resultcode == result_ok) {      if (requestcode == select_picture) {          uri selectedimageuri = data.getdata();          selectedimagepath = getpath(selectedimageuri);          edittext imagebrowse = (edittext)findviewbyid(r.id.thumb_url);          imagebrowse.settext(selectedimagepath);          byte[] strbytes = converttobytes(selectedimagepath);           imagebytes = strbytes;      }  } } 

converttobytes method should this:

public byte[] converttobytes(string selectedimagepath) {  try  {   fileinputstream fs = new fileinputstream(selectedimagepath);    bitmap bitmap = bitmapfactory.decodestream(fs);    bytearrayoutputstream boutput = new bytearrayoutputstream();    bitmap.compress(compressformat.jpeg,1, boutput);    byte[] dataimage = boutput.tobytearray();    return dataimage;  }  catch(nullpointerexception ex)  {   ex.printstacktrace();   return null;  }   catch (filenotfoundexception e)  {         e.printstacktrace();     return null;  }  }   public string getpath(uri uri) {     string[] projection = { mediastore.images.media.data };     cursor cursor = managedquery(uri, projection, null, null, null);     int column_index = cursor          .getcolumnindexorthrow(mediastore.images.media.data);     cursor.movetofirst();     return cursor.getstring(column_index); } 

by can upload image.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -