I have the following intent -
binding.fragmentContactUsEmail.setOnClickListener {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "*/*"
putExtra(Intent.EXTRA_EMAIL, EMAIL)
putExtra(Intent.EXTRA_SUBJECT, "Team-It application feedback")
}
if (intent.resolveActivity(requireActivity().packageManager) != null) {
startActivity(intent)
}
}
Which does indeed open email intent.
The issue is that when trying to filter the intent using the docs from developer.android.com like this -
fun composeEmail(addresses: Array<String>, subject: String) {
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:") // only email apps should handle this
putExtra(Intent.EXTRA_EMAIL, addresses)
putExtra(Intent.EXTRA_SUBJECT, subject)
}
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
}
It failed the if statement like I do not have any email applications in my device, which is wrong as I do have one of them.
Another issue is that I can't get the Intent.EXTRA_EMAIL to work - it just does not add the e-mail addresses that should be delivered to, it leaves it blank.
What am I missing?
edit -
After trying a solution given to me in the comments, I was able to get the email send to an address but still title does not work.
Here is my current code -
binding.fragmentContactUsEmail.setOnClickListener {
val emailIntent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:${Constants.ApplicationContactInformation.EMAIL}")
putExtra(Intent.EXTRA_SUBJECT, "Feedback for Team-It")
}
if (emailIntent.resolveActivity(requireActivity().packageManager) != null) {
startActivity(Intent.createChooser(emailIntent, ""))
} else {
Toast.makeText(requireContext(), getString(R.string.contact_us_fragment_no_email_applications), Toast.LENGTH_SHORT).show();
}
}