I am new to this but what is wrong with my snippet of coding? I am getting the error: 'This action is not currently supported' when I select the link. Here is my code:
public void addEmail() {
TextView txt = (TextView) findViewById(R.id.emailtext);
txt.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
String uriText =
"mailto:[email protected]" +
"?subject=" + URLEncoder.encode("some subject text here") +
"&body=" + URLEncoder.encode("some text here");
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));
}});
}
Many thanks!
The problem is probably that you're running on one of the official Android emulators and you haven't yet set up an email account on it. The emulators open the com.android.fallback.Fallback
activity when this happens, but this doesn't seem to happen on real-world devices.
You can detect this before trying to start the intent using this code:
ComponentName emailApp = intent.resolveActivity(getPackageManager());
ComponentName unsupportedAction = ComponentName.unflattenFromString("com.android.fallback/.Fallback");
boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);
Try this, it worked for me :
public void addEmail() {
TextView txt = (TextView) findViewById(R.id.emailtext);
txt.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String[] emails = {"[email protected]"};
String subject = "your subject";
String message = "your message";
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, emails);
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
// need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With