Android : How do I send webview content body via email?

on Tuesday, April 14, 2015


Currently in my app, I am using a webview for my html content to be displayed(which is coming via assets folder as expected,just to clarify). However, I have integrated send via email functionality and I see the subject body and title as null instead of content in focus in the selected email of choice. (say I pick gmail when I select my send via email option. I see the content body as null instead of the content in the webview).Any one has done this or has an idea, how to go about the same? Here's my code: My 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 My Fragment class :



//The button where 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 do I go about the same?


Thanks!


0 comments:

Post a Comment