android - How do I send webview content body via email? -


currently in app, using webview html content displayed(which coming via assets folder expected,just clarify). however, have integrated send via email functionality , see subject body , title null instead of content in focus in selected email of choice. (say pick gmail when select send via email option. see content body null instead of content in webview).any 1 has done or has idea, how go same? here's code: emailutils class:

public class emailutils {     public static string feedback_email = "android.feedback@mycompany.com";      public static void sharenewsviaemail(final fragment fragment, final string emailsubject, final string emailbody){         sharenewsviaemailex(fragment.getactivity(), emailsubject, emailbody);     }      public static void sharenewsviaemailex(final context context, final string emailsubject, final string emailbody){         final intent emailintent = new intent(intent.action_send);         emailintent.settype("text/html");         final string subjectappendtext = " " + context.getresources().getstring(r.string.email_subject_append);         emailintent.putextra(intent.extra_subject, emailsubject + subjectappendtext);         emailintent.putextra(intent.extra_text, emailbody);         context.startactivity(intent.createchooser(emailintent, "send email"));     }  } 

part fragment class :

//the button it's called: @override     public void onmenuitemclicked(final int position) {         moptionsmenuhelper.hidemenu();         menubutton.setselected(false);         switch (position) {          case optionmenuitems.email_story_position:             emailarticle();             break;         }     }  private void emailarticle() {         final fragment fragment =  marticleadapter.getfragment(marticlepager.getcurrentitem());          if (fragment instanceof articlefragmentwebview)  {             final string emailsubject = ((articlefragmentwebview)fragment).getheadline();             final string articlebody  = ((articlefragmentwebview)fragment).getarticlebody();             final string newline = getresources().getstring(r.string.new_line);             final string disclamer = getresources().getstring(r.string.intellectual_property_info);             final string emailbody = articlebody + newline + disclamer;             emailutils.sharenewsviaemail(this, emailsubject, emailbody);         }     } 

how go same?

thanks! here's articlefragmentwebview:

public class articlefragmentwebview extends absbasearticlefragment {     public static final string tag_article_fragment = "articlefragment";     public static final string article_position = "article_position";     public static final string category_code = "article_code";     private int mpositioninpager;     private articlewebviewclient articlewebviewclient;      @override     public void onactivitycreated(final bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);         mpositioninpager = getarguments().getint(article_position);     }      @override     public view oncreateview(final layoutinflater inflater, final viewgroup container, final bundle savedinstancestate) {         final view view = super.oncreateview(inflater, container, savedinstancestate);         articlewebviewclient = new technicarticlewebviewclient(getactivity(), view);         return view;     }      @override     public void onloading() {             final view fragmentview = getview();             if (fragmentview != null) {                 layoututils.showloading(fragmentview, "");             }     }        @override     public void showloading(view view) {             layoututils.showloading(view, "");     }     @override     public void showresults(final uri uri) {             layoututils.showresults(getview(), r.id.news_body);     }        @override     public void settextsize(textsize textsize) {         articlewebviewclient.increasefontsize();     }     @override     public void shownoresults(final uri uri) {     //  layoututils.shownoresult(getview(), r.id.details_container);     }     @override     public void showrelateddivider() {      }     @override     protected void getrelatedquotes() {      }     @override     public uri oncreatecontenturi() {         final string articlecode = getarguments().getstring(article_code);         return uri.withappendedpath(newscontentprovider.article_mynews_uri, articlecode);     }         @override     public void onstart() {         super.onstart();     }      public int getpositioninpager() {         return mpositioninpager;     }      @override     protected int getfragmentlayoutid() {         return r.layout.fragment_article_briefcase;     }      @override     protected int getarticletextviewid() {         return r.id.news_body;     }      @override     protected int getflowtextviewid() {         return r.id.tv;     }      @override     protected int getheadertextviewid() {         return r.id.headline;     }      @override     protected int getmetadatatextviewid() {         return r.id.timestamp_and_source;     }      @override     public void onmenuitemclicked(final int position) {         //do nothing     }     @override     public boolean setviewvalue(final view view, final cursor cursor, final int columnindex) {         if (view.getid() !=  r.id.news_body)            // paranoia             return true;          string article = cursor.getstring(columnindex);         string storyid = cursor.getstring(cursor.getcolumnindex(briefcase.columns.id));         return articlewebviewclient.setarticle(article, storyid);     } } 

and here's model class getarticlebody:

public class briefcase {           public static final string text_type = "text";         public static final string html_type = "html";         public static final string pdf_type = "pdf";      public static class columns {          public static final string id = "id";         public static final string name = "name";         public static final string saved_date = "saveddate";         public static final string type = "documenttype";         public static final string document_date = "documentdate";         public static final string source = "documentsource";         public static final string document_link = "documentlink";         public static final string document_id = "documentid";         public static final string is_read = "isread";         public static final string article_body = "articlebody";         //primaryric     }      public briefcase(string id, string articleid, string name, string docdate, string source, string doctype){         mid = id;         mdocumentid = articleid;         mname = name;         mpnacdate = docdate;         mdocumentsource = source;         mdocumenttype = doctype;         misread = "false";         msaveddate = new date();     }      @serializedname(columns.id)     private string mid;      @serializedname(columns.name)     private string mname;      @serializedname(columns.saved_date)     private date msaveddate;      @serializedname(columns.type)     private string mdocumenttype;      @serializedname(columns.document_date)     private string mpnacdate;      @serializedname(columns.source)     private string mdocumentsource;      @serializedname(columns.document_id)     private string mdocumentid;      @serializedname(columns.is_read)     private string misread;      public string getid() {         return mid;     }      public string getname() {         return mname;     }      public date getsaveddate() {         return msaveddate;     }      public string getdocumenttype() {         return mdocumenttype;     }      public string getpnacdate() {         return mpnacdate;     }      public string getdocumentsource() {         return mdocumentsource;     }      public string getdocumentlink() {         string doclink = null;         if(stringutils.isempty(mdocumentsource))             return doclink;          return mdocumentid;      }      public string getisread() {         return misread;     }      public contentvalues tocontentvalues() {         if (hasvaliddata()) {             final contentvalues values = new contentvalues();             values.put(columns.id, mid);             values.put(columns.name, decodeheadline());             values.put(columns.saved_date, msaveddate.gettime());             values.put(columns.document_link, getdocumentlink());             values.put(columns.document_date, dateutils.convertfromutcstringtolong(mpnacdate));             values.put(columns.source, mdocumentsource);             values.put(columns.is_read, misread);             values.put(columns.type, mdocumenttype);             values.put(genericcolumns.user_id, sharedpreferencesmanager.getinstance().getloginusername());             return values;         }         return null;     }      private string decodeheadline() {         string decodedheadline = mname;         try {             decodedheadline = urldecoder.decode(mname, networkutils.values.utf_8);         } catch (final exception e) {             e.printstacktrace();         }         return decodedheadline;     }      public contentvalues tocontentfordatabaseupdatevalues() {         if (hasvaliddata()) {             final contentvalues values = tocontentvalues();             values.put(columns.article_body, getarticlebody());             return values;         }         return null;     }      private string getarticlebody() {         string body = "";         final contentresolver resolver = application.getappcontext().getcontentresolver();         final string[] projection = new string [] {columns.article_body};         final uri uri = uri.withappendedpath(briefcasecontentprovider.briefcase_article_story_uri, mid);         final cursor cursor = resolver.query(uri, projection, null, null, null);         if(cursor.getcount()>0){             cursor.movetofirst();             body = cursor.getstring(cursor.getcolumnindex(columns.article_body));         }         return body;     }      private boolean hasvaliddata() {         boolean isvalid = false;         if (stringutils.isnotempty(mid) && stringutils.isnotempty(mname)){             isvalid = true;         }         return isvalid;     }  } 

have tried html.fromhtml(string). code below works great displaying html in email me

final intent emailintent = new intent(android.content.intent.action_send); string body = convertstreamtostring(getresources().openrawresource(r.raw.share_email_body)); emailintent.settype("text/html"); emailintent.putextra(android.content.intent.extra_subject, "my subject"); emailintent.putextra(android.content.intent.extra_text, html.fromhtml(body)); startactivity(intent.createchooser(emailintent, "email:")); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -