Android Email Intent Tutorial - How to Send Email From Within Your App

  Рет қаралды 14,934

Coding Demos

Coding Demos

4 жыл бұрын

Hi and welcome to another tutorial from CodingDemos :)
In this tutorial, you will learn how to send an email by clicking on a button.
You will learn how to use the Android ACTION_SENDTO and ACTION_SEND Intent to be able to send an email from your app.
Here are the steps:
1- Open up Android Studio.
2- Inside Button onClickListener declare Android ACTION_SENDTO Intent like this.
Intent intent = new Intent(Intent.ACTION_SENDTO);
3- Next, you need to set the SendTo email field like this.
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email.getText().toString()});
4- You need to set the subject of the email like this.
intent.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
5- You also need to set the email body like this.
intent.putExtra(Intent.EXTRA_TEXT, body.getText().toString());
6- You need to add the following code in order to show only the email applications inside the device that can support this action.
intent.setData(Uri.parse("mailto:"));
7- Before you start the Intent, you need to check in your device whether there is an email application that can support this action. If you don't do that and your device doesn't have an application, the app will crash. Here how you can do the checking.
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "There is no application that support this action",
Toast.LENGTH_SHORT).show();
}
If the device has an application that supports this action, then it will call startActivity(intent). Otherwise, it will show a Toast message with an error.
8- Now build and run the app to see the result :)
Links:
Android ACTION_DIAL Intent: developer.android.com/guide/c...
Website: www.codingdemos.com
FaceBook: / codingdemos

Пікірлер: 36
@CodingDemos
@CodingDemos 4 жыл бұрын
Hey guys, I hope you liked this tutorial :) Comment below on topics you want me to cover next.
@BlackVoid1998
@BlackVoid1998 3 жыл бұрын
I am literally afraid by your subscribe button sound 1:30
@abbbdddulqadeeer931
@abbbdddulqadeeer931 4 жыл бұрын
Keep going, nace android tutorial, thanks.🧡
@mysticwolveandfriends8057
@mysticwolveandfriends8057 Жыл бұрын
Love you brother, I thought i was going to spend hours to insert that feature in phone but you made it very easy. Respect from 🇵🇰
@mysticwolveandfriends8057
@mysticwolveandfriends8057 Жыл бұрын
If you made any video about sharing a pdf please tell me
@zona7822
@zona7822 2 жыл бұрын
thank you for your explaining. you are very objective🤠🤠🤠
@shreyancebodh5866
@shreyancebodh5866 3 жыл бұрын
nice job!! thankyou!!
@xhera2812
@xhera2812 2 жыл бұрын
it's really helpful thanx bro
@Revitalish
@Revitalish 2 жыл бұрын
thank you for explaining! What if I have more than one emailing app but I want it to use my default email app only?
@gokulvassanelango699
@gokulvassanelango699 3 жыл бұрын
thanks bro..................... this code only working correctly
@ThugKostya
@ThugKostya 3 жыл бұрын
Many thanks !!!!!!!!!!!!!!!!!!!!!!!!!
@CodingDemos
@CodingDemos 3 жыл бұрын
You're welcome 😃
@seino__
@seino__ 3 жыл бұрын
1:21 ooff that sound gave me a panic attack!
@CodingDemos
@CodingDemos 3 жыл бұрын
I'm sorry about that. I can't turn it off because the video is already published.
@seino__
@seino__ 3 жыл бұрын
@@CodingDemos Can understand, but the video really helped me! thank u so much
@CodingDemos
@CodingDemos 3 жыл бұрын
You're welcome 😀
@remo899
@remo899 2 жыл бұрын
Hey i want to pass setType("plain/text") too but when i applied it with setDataandType its not work can u plz help me, what should i do ????
@LamijaSahat
@LamijaSahat Жыл бұрын
Hi, great video but how do I set the sender's mail? Because with this code it sets the email you input as the sender's mail not recipient's.
@kaylinkhalil5119
@kaylinkhalil5119 Жыл бұрын
bro..this video helped me a lot.. but please fix that jump scare subscribe thing that keeps scarring me cause it comes from nowhere at a loud sound making me jump every time🤣🙂 😂 i almost trashed my headsets out of shock😧😧😱😱🥺🥺🥺🥺
@DsCanalS
@DsCanalS 2 жыл бұрын
0:55hrs screamer 1:20 second this video 🤣
@mhmadanteer9324
@mhmadanteer9324 2 жыл бұрын
Why It worked with emulator , but when i test it in my phone it didnt work?
@damonhue8174
@damonhue8174 3 жыл бұрын
Hey so when I tap the send button it doesn't do anything & I have all the codes correct did I miss something like a dependency or ....
@CodingDemos
@CodingDemos 3 жыл бұрын
Hi, is there any error message in the logcat?
@damonhue8174
@damonhue8174 3 жыл бұрын
@@CodingDemos No it doesn't show anything only in the build output it says "duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.3.1-runtime (android.core:core:1.3.1) and support-v4-22.2.0-runtime" thats all that pops up when I try to run it
@damonhue8174
@damonhue8174 3 жыл бұрын
@@CodingDemos so it doesn't show the send or cancel link on it but its popping up now I have all the same codes but its not showing that part
@maha-bv7cg
@maha-bv7cg 2 жыл бұрын
same problem here, did you know how to fix it ?
@mutiathul1811
@mutiathul1811 3 жыл бұрын
I want to take picture with camera and send it to email , can you help me??
@heatherwang8517
@heatherwang8517 3 жыл бұрын
Same question
@bhaskar_blur
@bhaskar_blur 2 жыл бұрын
@@heatherwang8517 open a camera intent, startactivityforresult , in result get the uri of result and convert it to bitmap or any other email image supporting format and put that as extras in email intent
@shynx1974
@shynx1974 2 жыл бұрын
someone help me with this error ;-; i followed the codes error: cannot find symbol if(intent.resolveActivity(getPackageManager()) != null ) { ^ symbol: method getPackageManager()
@CodingDemos
@CodingDemos 2 жыл бұрын
Hi, are you using activity or fragment?
@shynx1974
@shynx1974 2 жыл бұрын
@@CodingDemos fragment
@CodingDemos
@CodingDemos 2 жыл бұрын
Please use getActivity().getPackageManager()
@shynx1974
@shynx1974 2 жыл бұрын
@@CodingDemos i did but it says that that "There is no application that support this action"
@CodingDemos
@CodingDemos 2 жыл бұрын
Can you please try to test it on a real device?
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 5 МЛН
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 96 МЛН
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Гараж 54
Рет қаралды 14 МЛН
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 54 МЛН
How to Add Contacts Programmatically in Android
19:33
Coding Demos
Рет қаралды 13 М.
Writing Tablet Drawing Board Children'
0:13
Ctoytown
Рет қаралды 18 М.
Send Email using Intent - Android Studio - Java
13:46
Atif Pervaiz
Рет қаралды 14 М.
Android Firebase Send a User a Verification Email (Explained)
21:55
Flutter - What is a Widget - Part 4
1:27
Unreal Flutter
Рет қаралды 66
How to Insert an Event to Calendar Using Android Intent
18:28
Coding Demos
Рет қаралды 37 М.
[Android] 4. Зачем нужен GitHub? Выкладываем свой первый проект
11:40
BeTry | Программирование
Рет қаралды 4,9 М.
How to send email using gmail SMTP server directly from your Android App?
17:59
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 5 МЛН