Mailto Android: Unconfirmed Action Error

I'm new to this, but what's wrong with my code snippet? I get an 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: youremail@gmail.com " + "?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!

+5
source share
2 answers

Probably the problem is that you are working on one of the official Android emulators, and you have not yet created an email account on it. Emulators open com.android.fallback.Fallback activity when this happens, but this does not seem to happen on real devices.

You may discover this before attempting to run an intent with this code:

 ComponentName emailApp = intent.resolveActivity(getPackageManager()); ComponentName unsupportedAction = ComponentName.unflattenFromString("com.android.fallback/.Fallback"); boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction); 
+13
source

Try it, 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 = {" youremail@gmail.com "}; 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 :")); }}); } 
+1
source

Source: https://habr.com/ru/post/1209365/


All Articles