parse.com - Image capture, Save file...Android/Parse -
i attempting save image file captured mobile parse, within android app. using final file mediafile. think problem is, know need convert file byte array...i've tried various ways this. can see image in preview...but can't seem save parse.
thanks help.
public uri getoutputmediafileuri(int type) { return uri.fromfile(getoutputmediafile(type)); } /** * returning image / video */ private file getoutputmediafile(int type) { // external sdcard location string appname = cameraactivity.this.getstring(r.string.app_name); file mediastoragedir = new file( environment .getexternalstoragepublicdirectory(environment.directory_pictures), appname); // create storage directory if not exist if (!mediastoragedir.exists()) { if (!mediastoragedir.mkdirs()) { log.d(appname, "oops! failed create " + appname + " directory"); return null; } } // create media file name string timestamp = new simpledateformat("yyyymmdd_hhmmss", locale.getdefault()).format(new date()); final file mediafile; if (type == media_type_image) { mediafile = new file(mediastoragedir.getpath() + file.separator + "img_" + timestamp + ".jpg"); } else { return null; } final parsefile photofile; fileinputstream fileinputstream=null; byte[] bfile = new byte[(int) mediafile.length()]; try { //convert file array of bytes byte[] data2; fileinputstream fis = new fileinputstream(mediafile); filechannel fc = fis.getchannel(); int sz = (int)fc.size(); mappedbytebuffer bb = fc.map(filechannel.mapmode.read_only, 0, sz); data2 = new byte[bb.remaining()]; bb.get(data2); // save image parse photofile = new parsefile("profile_photo.jpg", data2); photofile.saveinbackground(); mcurrentuser.getcurrentuser(); mcurrentuser.put("profilephoto", photofile); mcurrentuser.saveinbackground(); system.out.println("done"); }catch(exception e) { e.printstacktrace(); } return mediafile; } }
i have try , work me...!
currentuser = parseuser.getcurrentuser(); bytearrayoutputstream stream = new bytearrayoutputstream(); // compress image lower quality scale 1 - 100 //here bitmap selected photo's bitmap bitmapprofilepic.compress(bitmap.compressformat.png, 100, stream); byte[] image = stream.tobytearray(); final parsefile file = new parsefile("profile.png", image); file.saveinbackground(new savecallback() { @override public void done(parseexception e) { if (e == null) { currentuser.put("profilephoto", file); currentuser.saveinbackground(new savecallback() { @override public void done(parseexception e) { if (e == null) { toast.maketext(context, "updated..!!", toast.length_long).show(); } } }); toast.maketext(context, "picture updated..!!", toast.length_long).show(); } else { toast.maketext(context, "error " + e.getmessage(), toast.length_long).show(); } } });
in case have byte data in data2 so,...
final parsefile file = new parsefile("yourphotoname.jpg", data2); file.saveinbackground(new savecallback() { @override public void done(parseexception e) { if (e == null) { currentuser.put("profilephoto", file); currentuser.saveinbackground(new savecallback() { @override public void done(parseexception e) { if (e == null) { toast.maketext(context, "updated..!!", toast.length_long).show(); } } }); toast.maketext(context, "picture updated..!!", toast.length_long).show(); } else { toast.maketext(context, "error " + e.getmessage(), toast.length_long).show(); } } });
Comments
Post a Comment