Can't upload image capture from camera android -
i'm trying write small code allows me send picture directly after taking camera, want send pict capture in camera never sucess, i'm message "something went wrong" there code
public void loadimagefromgallery(view view) { charsequence colors[] = new charsequence[] {"galery", "foto"}; alertdialog.builder builder = new alertdialog.builder(userprofileactivity.this); builder.settitle("pilih"); builder.setitems(colors, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { if (which == 0) { intent galleryintent = new intent(intent.action_pick, android.provider.mediastore.images.media.external_content_uri); startactivityforresult(galleryintent, result_load_img); } else if (which == 1) { intent intent = new intent("android.media.action.image_capture"); //intent.putextra(mediastore.extra_output, fileuri); startactivityforresult(intent, camera_request); } } }); builder.show(); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); try { if(requestcode == camera_request){ bitmap photo = (bitmap) data.getextras().get("data"); roundedimageviewutil imgview = (roundedimageviewutil) findviewbyid(r.id.profile); imgview.setimagebitmap(photo); uri selectedimage = data.getdata(); string[] filepathcolumn = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(selectedimage, filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); imgpath = cursor.getstring(columnindex); cursor.close(); imgview.setimagebitmap(bitmapfactory .decodefile(imgpath)); string filenamesegments[] = imgpath.split("/"); filename = filenamesegments[filenamesegments.length - 1]; params.put("filename", filename); } else if (requestcode == result_load_img && resultcode == result_ok && null != data) { uri selectedimage = data.getdata(); string[] filepathcolumn = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(selectedimage, filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); imgpath = cursor.getstring(columnindex); cursor.close(); roundedimageviewutil imgview = (roundedimageviewutil) findviewbyid(r.id.profile); imgview.setimagebitmap(bitmapfactory .decodefile(imgpath)); string filenamesegments[] = imgpath.split("/"); filename = filenamesegments[filenamesegments.length - 1]; params.put("filename", filename); } else { toast.maketext(this, "you haven't picked image", toast.length_long).show(); } } catch (exception e) { toast.maketext(this, "something went wrong", toast.length_long) .show(); } }
intead of
bitmap photo = (bitmap) data.getextras().get("data");
try
uri imageuri = (uri)data.getdata();
and uri image bitmap.
Comments
Post a Comment