Android share intent with html text

 The following will launch a bottom sheet with a list of apps and let you pick an app to share the content. For example, if you picked an email app, it will populate the subject and body in that email app. The example text here contains html tags, by setting the type to “text/html”, and parse the html content using HtmlCompat.fromHtml, it will renders the html in the email app or any other app that can handle html contents.

val shareIntent = Intent(android.content.Intent.ACTION_SEND)
shareIntent.type = "text/html"
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Android Notification")
shareIntent.putExtra(Intent.EXTRA_TEXT, HtmlCompat.fromHtml("<h1>Title</h1><p>This is a body</p>", HtmlCompat.FROM_HTML_MODE_LEGACY))
startActivity(Intent.createChooser(shareIntent, "Share with:"))

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...