Sending an email via an intent - android

I am currently working on an android project and I am adding a preference to be able to send me an email. I am using the ACTION_SENDTO intent to send the email but its coming back and says No apps can perform this action.
Below is the code I am using
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "someone#example.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Check out this android app");
intent.putExtra(Intent.EXTRA_TEXT, "Check out this new app in the Google Play Store. Its from Boardies IT Solutions and is called Boardies Password Manager. You can find it at https://play.google.com/store/apps/details?id=com.BoardiesITSolutions.PasswordManager");
startActivity(Intent.createChooser(intent, "Send Email"));
Thanks for any help you can provide

You need to add the following
intent.setData(Uri.parse("mailto:" + "email#bla.com")); // leave
blank if not specificity

I think you should replace Intent.ACTION_SENDTO to Intent.ACTION_SEND,
Hope this will work for you.
How about this code:
final Intent emailLauncher = new Intent(Intent.ACTION_SEND);
emailLauncher.setType("message/rfc822");
emailLauncher.putExtra(Intent.EXTRA_EMAIL, "username#domain.com");
emailLauncher.putExtra(Intent.EXTRA_SUBJECT, "check this subject line");
emailLauncher.putExtra(Intent.EXTRA_TEXT, "hey check this message body!");
try{
startActivity(emailLauncher);
}catch(ActivityNotFoundException e){
}

Related

How to make app picker for sharing text permanent in Android?

I'm trying to make refer and earn activity in my appSo I want to permanently display a few apps like whatsapp, etc for the user to click on them and share directly.I'm using Intent to share the referral code but it pops up the apps list when the user clicks share.The code I'm using is,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "This is a message");
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Share via"));
How can I make the app chooser permanent for a few apps?
The app chooser is not intended to be displayed permanently. Therefore you will have to create simple buttons or icons and create an intent that refers to the desired app directly, by setting the package of the intent.
E.g. to share sth with WhatsApp use sth like this:
Intent sendIntent = new Intent();
// here comes the magic
sendIntent.setPackage("com.whatsapp");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Depending on the type of content you want to share and the apps you want to share with, it makes sense to reuse the code to create the intent and just set the respective package and eventually some additional parameters.
You will need package name of app and a Intent.
change ACTION_VIEW to ACTION_SENDTO
set the Uri as you did set the
package to whatsapp
Intent i = new Intent(Intent.ACTION_SENDTO,
Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.setType("text/plain");
i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);
You can refer this link for More:
Send text to specific contact (whatsapp)
Sending message through WhatsApp
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "your text content");
startActivity(intent)
I am facing same problem for share tamil font content in Whatsapp. I found the solution, this setType("*/*") share full content.

Android intent not showing only email clients

So I'm trying to launch a prepopulated email client with data. The content gets populated fine, however my problem is that when launching the intent, I wanted it to only show email clients to select from.
Instead, it shows Gmail, Adding to EverNote, Android Beam, Bluetooth, and some others.
I don't know if its an issue with lollipop that broke this functionality or not, as one of my managers sent me code that worked fine for him a few years ago.
My code is:
private void openEmailClient(){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{getResources().getString(R.string.contact_feedback_email_address)});
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.contact_feedback_email_subject_android));
try{
startActivity(Intent.createChooser(intent,intentEmailString));
} catch(android.content.ActivityNotFoundException ex){
Log.e(EMAIL_FAIL_TAG, EMAIL_FAIL);
ex.printStackTrace();
}
}
when you will change your intent.setType like below you will get
intent.setType("text/plain");
Use
android.content.Intent.ACTION_SENDTO
(new Intent(Intent.ACTION_SENDTO);) to get only the list of e-mail clients, with no facebook or other apps. Just the email clients.
I wouldn't suggest you get directly to the email app. Let the user choose his favorite email app. Don't constrain him.
If you use ACTION_SENDTO, putExtra does not work to add subject and text to the intent. Use Uri to add the subject and body text.
We can use message/rfc822 instead of "text/plain" as the MIME type. However, that is not indicating "only offer email clients" -- it indicates "offer anything that supports message/rfc822 data". That could readily include some application that are not email clients.
message/rfc822 supports MIME Types of .mhtml, .mht, .mime
EDIT
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:someone#example.com"));
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);
its working ...
So I solved it. Not ideally but it works better than anything else I have tried.
I followed the google docs on doing it, which says to do this:
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
and it now works.
This just finds a default app for handling mail. I'm not sure how it decides, but in my case it opened GMail. On a device without GMail installed, such as the Galaxy S5, it opened their mail client and prompted the user to set up email.
Doesn't give choice of app but it works
Try like this it working fine for me...
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:abc#gmail.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "Test App");
intent.putExtra(Intent.EXTRA_TEXT, "Email Body");
startActivity(intent);
Note: it only work if you have email address.
For more information please refer this link Android - Is there a foolproof way to only show possible EMAIL clients?

How to set action, category and data for intent?

I'm programming an Android application. I want to invoke other applications to perform certain operations(Sending emails etc.) How do I know which action and category to set for the intent? Should I look other application's intent filter? What if that application is not open source?
Also, for the data or extra attribute, I don't know how the 3rd party application will handle my intent, so I do not know how to set the attributes. For example, I want one string as the title of the email, one string as the content of the email, and another string as the recipient, and a picture as the attachment. Can I include all these information in the intent? What if the 3rd party application don't provide any functionality to handle it?
Usually, for common tasks in Android there is a general Intent that you send on which other applications can register.
for example to share some text you would create an intent like:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
will prompt android's native share dialog on which the user can choose how he wants to share it.
Specifically for email you would do something like:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","email#domain.com", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "This is my email subject");
startActivity(Intent.createChooser(intent, "Email"));
Other examples may be to launch the default sms application:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
sendIntent.putExtra("sms_body", getMessageBody());
Or open the phone's dialer:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+number));
startActivity(intent);
You need to figure out what are the actions that you want to implement in your app and then figure out how to implement each of them.
You can find some more data here:
Android content sharing
Android intents - under the various intent actions
Try using category and actions in intent.
Intent mailIntent = new Intent(Intent.ACTION_SEND);
mailIntent.setType("text/plain");
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Reporting mail");
mailIntent.putExtra(Intent.EXTRA_TEXT, "Some message");
mailIntent.putExtra(Intent.EXTRA_EMAIL, "xxx#yyy.com");
startActivity(mailIntent);
this is an example for sending email. For further details refer http://developer.android.com/guide/components/intents-common.html

How to know which application the user chose when using an intent chooser?

I'm using an intent chooser to invite friends :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("InvitationSubject", getBaseContext()));
String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
intent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(intent, "Invite friends"));
Is there a way to know which app the user selected in the chooser ?
As far as I know, there is no direct way to gather such information. What would you need it for? Imho the android intent system was designed so you, as an app developer, don't have to worry about what app the user chose to handle your intent.

How to start an application with an intent?

I want to start an intent to start Facebook with some extras. How can I do that?
Intent intent = new Intent(<????>);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
intent.putExtra(Intent.EXTRA_TEXT, "Check that");
startActivity(intent);
There is no sure way of doing this as the actions the Facebook application responds to may change and may not be publicly known. Here is a way to bring up a dialog which Facebook may respond to:
startActivity(
new Intent(Intent.ACTION_SEND)
.setType("image/png")
.putExtra(Intent.EXTRA_SUBJECT, "")
.putExtra(Intent.EXTRA_STREAM, uri)
.putExtra(Intent.EXTRA_TEXT, "")
);
uri is a reference to a PNG image on disk
I ended up using the Facebook Android SDK.

Categories

Resources