Android : Download and Share html file issue -


in application want download , share 1 html file. tried following code:

button download = (button) findviewbyid(r.id.downloadbtn);         download.setonclicklistener(new onclicklistener() {              public void onclick(view v) {                 string file_url= "/* http url*/";                  new downloadfilefromurl().execute(file_url);              }         });  }   class downloadfilefromurl extends asynctask<string, string, string> {          /**          * before starting background thread          * show progress bar dialog          * */         @override         protected void onpreexecute() {             super.onpreexecute();             showdialog(progress_bar_type);         }          /**          * downloading file in background thread          * */         @override         protected string doinbackground(string... f_url) {             int count;             try {                 url url = new url(f_url[0]);                 urlconnection conection = url.openconnection();                 conection.connect();                 // getting file length                 int lenghtoffile = conection.getcontentlength();                  // input stream read file - 8k buffer                 inputstream input = new bufferedinputstream(url.openstream(), 8192);                 string filepath = environment.getexternalstoragedirectory().tostring() + "/sridhar.html";                 // output stream write file                 outputstream output = new fileoutputstream(filepath);                  byte data[] = new byte[1024];                  long total = 0;                  while ((count = input.read(data)) != -1) {                     total += count;                     // publishing progress....                     // after onprogressupdate called                     publishprogress(""+(int)((total*100)/lenghtoffile));                      // writing data file                     output.write(data, 0, count);                 }                  // flushing output                 output.flush();                  // closing streams                 output.close();                 input.close();              } catch (exception e) {                 log.e("error: ", e.getmessage());             }              return null;         }          /**          * updating progress bar          * */         protected void onprogressupdate(string... progress) {             // setting progress percentage             pdialog.setprogress(integer.parseint(progress[0]));        }          /**          * after completing background task          * dismiss progress dialog          * **/         @override         protected void onpostexecute(string file_url) {             // dismiss dialog after file downloaded             dismissdialog(progress_bar_type);              goshare();         }      }     public void goshare(){          string filepath = environment.getexternalstoragedirectory().tostring() + "/sridhar.html";             // setting downloaded image view          log.e("downloaded path","path "+filepath);          uri fileuri = uri.fromfile(getfilestreampath(filepath));             //  mimetypemap mymime = mimetypemap.getsingleton();             //string mimetype = mymime.getmimetypefromextension("html");             //file file = new file(imagepath);             intent shareintent = new intent();             shareintent.setaction(intent.action_send);            // shareintent.setdataandtype(uri.fromfile(file),mimetype);            // shareintent.setflags(shareintent.flag_activity_new_task);             shareintent.putextra(intent.extra_stream, fileuri);             shareintent.settype("text/html");             startactivity(intent.createchooser(shareintent,"share"));     } 

the problem , can able download html file cant share ... i.e can able bring share context menu , selecting gmail, file not accepted gmail app , forces gmail app close.

and progress bar not working...

please provide me best way share downloaded file..

i have found solution :

intent shareintent = new intent();  shareintent.setaction(intent.action_send);  shareintent.putextra(intent.extra_stream, uri.fromfile(new file(filepath)));  shareintent.settype("text/html");  startactivity(intent.createchooser(shareintent,"share")); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -