I tried to send mail using with intent but it didn't work.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{adres});
intent.putExtra(Intent.EXTRA_SUBJECT, konu);
intent.putExtra(Intent.EXTRA_TEXT, icerik);
startActivity(intent);
try this:
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
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 :"));
Try to add below line:
startActivity(Intent.createChooser(intent, "Send email with: "));
Related
enter image description here
the email intent code is completely run in the android mobile model provided by android studio but when I run the code in my personal phone its not work…
please answer ??
Don't forget to set the type of intent so it will trigger email clients
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
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 :"));
Kotlin code,
val selectorIntent = Intent(Intent.ACTION_SENDTO)
selectorIntent.data = Uri.parse("mailto:")
val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf<String>("mail id"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject")
emailIntent.selector = selectorIntent
startActivity(Intent.createChooser(emailIntent, "Send email..."))
Java code,
Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"mail id"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.setSelector(selectorIntent);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Intent intEmail = new Intent(Intent.ACTION_SENDTO);
intEmail.setType("plain/text");
intEmail.setData(Uri.parse("mailto:"));
intEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"receiver_email_address"});
if (intEmail.resolveActivity(getPackageManager()) != null){
startActivity(intEmail);
}
I tested the code of mayar hassan, it worked fine on my side. [on Samsung Android 8.1]
The code:
public class TestSentMail extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_sent_mail);
Button button = findViewById(R.id.submitButton);
button.setOnClickListener(view -> {
submitOrder();
});
}
private void submitOrder() {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT, "coffe order for tancolo");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
}
The screenshot:
How to fix your problem
In general, I think we should do these as below.
Check the log in the Logcat panel in Android Studio, maybe there are exceptions.
Added your debug code where you want to add.
val i = Intent(Intent.ACTION_SEND)
i.type = "message/rfc822"
i.putExtra(Intent.EXTRA_EMAIL, arrayOf<String>("sumsolutions.net#gmail.com"))
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback")
i.putExtra(Intent.EXTRA_TEXT, "Text here...")
try {
startActivity(Intent.createChooser(i, "Send mail..."))
} catch (ex: ActivityNotFoundException) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT)
.show()
}
After google policy changed to not use SEND_SMS. I am using sms intent to send sms with custom message and sender address auto populated. It work in almost all mobile. But only in oneplus mobiles, receipent address is not getting populated
private void sendSMS(String phoneNumber, String message) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity());
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.putExtra("address",phoneNumber);
sendIntent.putExtra("exit_on_sent", true);
if (defaultSmsPackageName != null)
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivity(sendIntent);
}
else
{
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address",phoneNumber);
smsIntent.putExtra("sms_body",message);
startActivity(smsIntent);
}
}
I also tried
Intent sendIntent =new Intent(Intent.ACTION_VIEW);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.putExtra("address",phoneNumber);
sendIntent.putExtra("exit_on_sent", true);
sendIntent.setData(Uri.parse("smsto:" + phoneNumber));
and
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("address", phoneNumber);
intent.putExtra("sms_body", message);
intent.setData(Uri.parse("smsto:" + phoneNumber));
intent.putExtra("exit_on_sent", true);
None are working in oneplus mobiles(3, 7 and 7 pro). It is working in all MI phone, Samsung, Nokia, Honor, Motorola, Lenovo etc. Only in oneplus phone having issue.
I have tried below and it successfully worked for me. Tested on One Plus 3t.
String phoneNumber="+91xxxxxxxxxx";
String message ="Hi ABZ";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
startActivity(intent);[![enter image description here][1]][1]
I just wanted to open the Gmail app through my app and wanted to set email, subject and message from my application.
I have tried GmailService but it is not supporting bcc or cc emails.
Link: https://github.com/yesidlazaro/GmailBackground
BackgroundMail.newBuilder(this)
.withUsername("username#gmail.com")
.withPassword("password12345")
.withMailto("toemail#gmail.com")
.withType(BackgroundMail.TYPE_PLAIN)
.withSubject("this is the subject")
.withBody("this is the body")
.withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
#Override
public void onSuccess() {
//do some magic
}
}).withOnFailCallback(new BackgroundMail.OnFailCallback() {
#Override
public void onFail() {
//do some magic
}
}).send();
I would like to use bcc and cc functionality along with the attachment, subject, and message.
// For Email by Any app
Intent email= new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto:your.email#gmail.com"));
email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
email.putExtra(Intent.EXTRA_TEXT, "My Email message");
startActivity(email);
open gmail via Intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("abc#gmail.com"));
intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_CC, new String[]{"xyz#gmail.com"});
intent.putExtra(Intent.EXTRA_BCC, new String[]{"pqr#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "your subject goes here...");
intent.putExtra(Intent.EXTRA_TEXT, "Your message content goes here...");
startActivity(intent);
just pass EXTRA_CC & EXTRA_BCC in intent argument
Edit
Below answer will work on android 11
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"abc#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");
intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");
startActivity(intent);
Edit 2
val selectorIntent = Intent(Intent.ACTION_SENDTO)
selectorIntent.data = Uri.parse("mailto:")
val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("recipient#mail.com"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here...")
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email Body...")
emailIntent.selector = selectorIntent
activity!!.startActivity(Intent.createChooser(emailIntent, "Send email..."))
// This is for Gmail App
Intent email= new Intent(Intent.ACTION_VIEW);
email.setType("message/rfc822")
.setData(Uri.parse("mailto:your.email#gmail.com"))
.putExtra(Intent.EXTRA_EMAIL, "your.email#gmail.com")
.putExtra(Intent.EXTRA_SUBJECT, "Subject")
.putExtra(Intent.EXTRA_TEXT, "My Email message")
.setPackage("com.google.android.gm");
startActivity(email);
I m using this to launch gmail app.
val intent: Intent? = activity.packageManager.getLaunchIntentForPackage("com.google.android.gm")
if (intent != null) {
startActivity(intent)
}
else{
showToast("Sorry...You don't have gmail app")
}
//This is open with gmail
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("text/plain");
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Mail Subject");
i.putExtra(Intent.EXTRA_TEXT , "massage");
i.setPackage("com.google.android.gm");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(AnotherActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
I am using this
Intent mailClient = new Intent(Intent.ACTION_VIEW);
mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
startActivity(mailClient);
you can also try this
final Intent intent = new Intent(Intent.ACTION_VIEW)
.setType("plain/text")
.setData(Uri.parse("test#gmail.com"))
.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail")
.putExtra(Intent.EXTRA_EMAIL, new String[]{"test#gmail.com"})
.putExtra(Intent.EXTRA_SUBJECT, "test")
.putExtra(Intent.EXTRA_TEXT, "hello. this is a message sent from my demo app :-)");
startActivity(intent);
use for plenty of emails:
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test#gmail.com" });
for single emails:
intent.setData(Uri.parse("test#gmail.com"));
I have this code which is working completely error free, but not as per the expected output. When it runs it should provide a choice on how to send a mail, but it provides me with only Bluetooth and messenger not email.
protected void sendEmail() {
Toast.makeText(MainActivity.this,"Sending mail", Toast.LENGTH_SHORT).show();
String[] TO = {"xyz#gmail.com"};
String[] CC = {"abc#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message :");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
use this
protected void sendEmail() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:aaaaaa#gmail.com"));
emailIntent.putExtra("subject", "Feedback");
emailIntent.putExtra("body", "");
startActivity(emailIntent);
}
I tried this code,
I chose Facebook app and went to post page, but the chosen text does not get displayed.
public void onShareClick(View v){
List<Intent> targetShareIntents=new ArrayList<Intent>();
Intent shareIntent=new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos=getPackageManager().queryIntentActivities(shareIntent, 0);
if(!resInfos.isEmpty()){
System.out.println("Have package");
for(ResolveInfo resInfo : resInfos){
String packageName=resInfo.activityInfo.packageName;
Log.i("Package Name", packageName);
if( packageName.contains("com.facebook.katana")){
Intent intent=new Intent();
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Text");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.setPackage(packageName);
targetShareIntents.add(intent);
}
}
if(!targetShareIntents.isEmpty()){
System.out.println("Have Intent");
Intent chooserIntent=Intent.createChooser(targetShareIntents.remove(0), "Choose app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}else{
System.out.println("Do not Have Intent");
showDialaog(this);
}
}
}
Why doesn't the chosen text to share Display on facebook? I read Facebook's policy and they do not allow this, yet other applications are able to do so. Is there some way I can achieve that?
Try this:
public void setupFacebookShareIntent() {
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(getApplicationContext());
shareDialog = new ShareDialog(this);
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("YOUR TITLE")
.setContentDescription("YOUR DESCRIPTION")
.setContentUrl(Uri.parse("http://xxxx.com/"))
.setImageUrl(Uri.parse("http://xxxx.com/"))
.build();
shareDialog.show(linkContent);
}