Do a share of the function, the text image in the form of CSV to share to the mail and other applications.
First, CSV comma-separated value file format (comma-separated values), plain text form, comma-delimited, row of data does not cross the line.
Picture converted to Base64 string
Publicstring WriteBase64 (string path) {//path picture pathbyte[] data =NULL; Try{InputStream in=NewFileInputStream (path); Data=New byte[In.available ()]; In.read (data); In.close (); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } returnbase64.encodetostring (data, base64.no_wrap); Note that this is base64.no_wrap}
Finally, return to base64.encodetostring (data, Base64.no_wrap), and note that Base64.no_wrap is used instead of base64.default. Default when the string is too long (RFC2045 the maximum of 76 characters per line), automatically add line breaks, affect use, with no_wrap resolution.
Generate and write CSV
PublicFile writecsv () {String path= Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/csv/"; CSV files path file csv=NewFile (path + "Knowyourteam.csv")); File PA=NewFile (path); if(!pa.exists ()) {Pa.mkdirs (); } if(!csv.exists ()) { Try{csv.createnewfile (); } Catch(IOException e) {e.printstacktrace (); } } Else { Try{csv.delete (); Write here if the file exists will delete the file to create a new file Csv.createnewfile (); } Catch(IOException e) {e.printstacktrace (); } } Try{bufferedwriter bw=NewBufferedWriter (NewFileWriter (CSV,true)); ArrayList<Person> list =NewPersondao ( This). Queryall (); Database Fetch person List for(person person:list) {//cyclic write to Person data (name,title,image) String img /c8>=writeBase64 (Person.getpicpath ()); Getpicpath () path Bw.write (Person.getname ()+ "," + person.gettitle () + "," +img); Bw.newline (); Line break, one group of Data} bw.close (); } Catch(IOException e) {e.printstacktrace (); } returncsv; }
Last Share
File csv =writecsv (); Intent sendintent=NewIntent (); Sendintent.setaction (Intent.action_send); Sendintent.putextra (Intent.extra_stream, Uri.fromfile (CSV)); Sendintent.putextra (Intent.extra_subject,"Knowyourteam Shared Data"); SimpleDateFormat DF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//Set Date formatSendintent.putextra (Intent.extra_text, "there is CSV." + Df.format (NewDate ())); Sendintent.settype ("Text/comma-separated-values"); StartActivity (Intent.createchooser (sendintent,"Share"));
Intent.action_send with Attachment send
Intent.createchooser (Sentintent, "share") can select apps that support this format to open sharing
Android text picture written to CSV (BASE64) and share