android - It creates the folder and file, but never attach it -
i´m new on this, can´t understand lot of technical speak yet... so, i´m working in personnal project, objective when user press share(top menu), takes screenshot , can send attachment, creates folder, file everytime send via email or whatever, attachies empty file. picked exemples here this. @ manifest i´ve added permission (write_external/internal, internet, camera, read_external)
share class:
public class sharescreen { file picfile; public void shareit(view view, context context) { string state = environment.getexternalstoragestate(); if (environment.media_mounted.equals(state)) { file picdir = new file(environment.getexternalstoragedirectory() + "/sos code"); if (!picdir.exists()) { picdir.mkdir(); } view.setdrawingcacheenabled(true); view.builddrawingcache(true); bitmap bitmap = view.getdrawingcache(); // date date = new date(); string filename = "soscode" + ".jpeg"; picfile = new file(picdir + "/" + filename); try { picfile.createnewfile(); fileoutputstream picout = new fileoutputstream(picfile); bitmap = bitmap.createbitmap(bitmap, 0, 0, bitmap.getwidth(), (int) (bitmap.getheight() / 1.2)); boolean saved = bitmap.compress(compressformat.jpeg, 100, picout); if (saved) { toast.maketext( getapplicationcontext(), "image saved device pictures " + "directory!", toast.length_short).show(); } else { // error } picout.close(); } catch (exception e) { e.printstacktrace(); } view.destroydrawingcache(); ((qractivity) context).callintent(); } else { // error } } public file getpicfile() { return picfile; } private context getapplicationcontext() { // todo auto-generated method stub return null; } private view findviewbyid(int qrrelative) { // todo auto-generated method stub return null; } }
activity:
public class qractivity extends actionbaractivity { view view; sharescreen screen; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_qr); view = (view) findviewbyid(r.id.qrrelative);// layout id typeface tf = typeface.createfromasset(getassets(),"verdanab.ttf"); textview titleqr = (textview) findviewbyid(r.id.titleqr); titleqr.settypeface(tf); } public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); return true; } public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.share: screen = new sharescreen(); screen.shareit(view.getrootview(), qractivity.this); break; default: break; } return true; } public void callintent() { intent sharecode = new intent(intent.action_send); sharecode.settype("application/image"); sharecode.putextra(intent.extra_stream, uri.parse(screen.getpicfile().getabsolutepath())); sharecode.putextra(android.content.intent.extra_subject, "sos code"); sharecode.putextra(android.content.intent.extra_text, "your sos code"); startactivity(intent.createchooser(sharecode, "share via")); } }
you need change this;
sharecode.settype("application/image"); sharecode.putextra(intent.extra_stream, uri.parse(screen.getpicfile().getabsolutepath()));
to
sharecode.settype("image/*"); sharecode.putextra(intent.extra_stream, uri.fromfile(screen.getpicfile()));
Comments
Post a Comment