send intent android code example
Example 1: android send email intent with chooser
class MailToExample{
private val url = "https://your_site_addres.xyz"
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mailto)
val settings: WebSettings = mWebView.settings
settings.javaScriptEnabled = true
settings.allowFileAccess = true
mWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, urlin: String?): Boolean {
if (urlin != null) {
if (urlin.contains("mailto:")) {
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.parse(urlin))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject")
emailIntent.putExtra(Intent.EXTRA_TEXT, "body")
startActivity(Intent.createChooser(emailIntent, "Send email"))
} else {
view?.loadUrl(urlin)
}
}
return true
}
}
mWebView.postUrl(url)
}
}
Example 2: share intent android
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
String shareMessage = "\n" + tvBlogTitle.getText().toString()+ "\n\n";
shareMessage = shareMessage + bundle.getString("link") + "\n\n";
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
startActivity(Intent.createChooser(shareIntent, "choose one"));