I'm a beginner at Android programming. I want to create specific email button on my program. (For example email adress is info@abcde.tv). When I click email button, mail program should open. How can I achieve this?
Asked
Active
Viewed 6,574 times
2 Answers
7
You need to start an intent with special option.
Here is an example from the web:
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
/* Send it off to the Activity-Chooser */
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
-
thanks mate.ı wrote this code but this code gave an error on "context.startA...".it is "context connot be resolved".what can ı do? – muhammedkasva Jul 06 '11 at 09:04
-
ı deleted word context.there is no error.but ı run our project.when ı push button,text that is "SEND MAİL... NO APPLİCATİONS CAN PERFORM THİS ACTİON" comes to screen. – muhammedkasva Jul 06 '11 at 09:10
-
I think I find the problem, because you need an application which can handle the intent. Try this: emailIntent.setType("text/plain"); //use this line in the emulator emailIntent.setType("message/rfc822") ; // use this line in real device – kameny Jul 06 '11 at 13:03
-
Corrected `"plain/text"` -> `"text/plain"` in the answer. – Jonik Oct 18 '13 at 10:04
2
If you're getting the No applications can perform this action error,
simply create an email account using your emulator.
Android can't send mail from a non-existing email account.
dsaltus
- 21
- 2