I had shown the HTML file content in WebView.That is available in SDCard, I need to send that HTML Content as a email in the same format(HTML).
Note: I don't want to send it from email client application.I need to send it without user interaction
At this other Answer there is a nice explanation of using javaMail API. and other option is you can use mailchamp library.
Yes, It is possible
1st off, give the manifest permission to
<uses-permission android:name="android.permission.INTERNET" />
then follow the tutorial
but little bit tricky, check this tutorial
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android
Do this way
String htmalContentFromSdcard = "";
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, "abc#gmail.com");
i.putExtra(Intent.EXTRA_SUBJECT, "Demosubject");
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(htmalContentFromSdcard));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
ting(getString(R.string.share_email_no_client));
}
Hope this helps you.
Related
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text.getText());
sendIntent.setType("message/rfc822");
startActivity(Intent.createChooser(sendIntent, "Send email with"));
this was my code.
I tried the send mail in emulator. But it shows the no application can perform this action. if anyone knows means tell me
Thanks in advance
You need to use text/plain
intent.setType("text/plain");
Also, the Intent.ACTION_SEND is made for sharing, you may want to use Intent.ACTION_SENDTO to only get the list of e-mail clients, or avoid sharing applications such as Facebook, Twitter, etc.
This worked for me
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail#yahoo.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
There's a better approach if you want to send mail: use Action.SEND_TO:
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:sample#mail.com"));
sendIntent.putExtra(Intent.EXTRA_TEXT, text.getText());
That will narrow down the searchlist.
NOTE: Make sure you have set up email account on emulator, else the Email application will not be in the handlers-list, and you'll get exception.
This means that there is no application that is registered for handling such kind of intent.
Edit:
Try setting the intent type to "text/plain"
emailIntent.setType("text/plain");
and/or set EXTRA_EMAIL to set the content of the email
sendIntent.putExtra(Intent.EXTRA_EMAIL, text.getText());
After trying everything as mentioned in the above comments, if you don't find your solution, Just set an email in the default email in Emulator. It works for me.
private fun sendMail(recipient: String, subject: String, message: String)
{
val mIntent = Intent(Intent.ACTION_SEND)
mIntent.data = Uri.parse("mailto:sample#gmail.com")
mIntent.type = "text/plain"
mIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient))
mIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
mIntent.putExtra(Intent.EXTRA_TEXT, message)
try {
startActivity(Intent.createChooser(mIntent, "Choose email client"))
Toast.makeText(this, "Hey !! We received your order :) ", Toast.LENGTH_LONG).show()
}catch (e:Exception){
e.printStackTrace()
Toast.makeText(this, "Sorry your order could not be sent :( ", Toast.LENGTH_LONG).show()
}
}
This code works for me, I was facing the same problem,
changing : "val mIntent = Intent(Intent.ACTION_SENDTO)" to
"val mIntent = Intent(Intent.ACTION_SEND)" solved the problem for me.
Hope my response would help the readers
This generally means that there is no application installed currently, that understands the request you're making.
In this instance I would hazard a guess that there is no email app installed on the emulator? Or possibly that it hasn't been set up.
I'm trying to send an HTML text from my app by email. So I have this code:
StringBuilder sb = new StringBuilder();
// Lots of HTML building code...
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, trip_to_manipulate.getTrip_name());
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(sb.toString()));
i.setType("message/rfc822");// to filter and display only email apps
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getActivity(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
But when I run this code I have whole bunch of apps showing up in the chooser:
I tried to start activity without createChoser, I tried to change type to text/html, I tried to use ACTION_SENDTO instead of ACTION_SEND, I tried them separately, I tried them combined, but I still got all these apps. Sometimes even more. And when they were combined the app crashed.
So is there a way to limit this list to email clients only?
ShareActionProvider provides share for every compatible app on the device. I would like to specify which apps I want to allow sharing, like only twitter and gmail for example.
How would I do this?
Google don't recommend that you share to specific apps as there are various different Twitter clients - it's better to just let people chose where they want to share it.
However, the following code will send the message "hello twitter" to twitter on a button press.
String message = "hello Twitter";
try {
//try to open the official twitter app
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
sharingIntent.setPackage("com.twitter.android");
startActivity(sharingIntent);
} catch (Exception e) {
//fallback on opening an internet browser
Log.e("Danielle", "exception=" + e.toString());
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, message);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri
.parse("https://mobile.twitter.com/compose/tweet"));
startActivity(i);
}
Hope that helps.
If you are ok with just using a popup, the answer by dacoinminster in this question How to filter specific apps for ACTION_SEND intent (and set a different text for each app) will do it.
But if you specifically want it to be an actionprovider dropdown, I have not find this solution either.
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){
}
I'm writing an Android app that needs to access GMail, and I'd like to do it the same way the SwiftKey does, by showing the user a (Google-hosted?) prompt to login to their Google account, like this:
Do you know what API they're using to get this prompt? Does this API provide direct access to GMail or do I still have to use IMAP?
Thanks in advance...
It seems like oauth being handled via webview which is constructed to look like dialog box.
You need to use Intent for your requirement. Following is the code for same.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{ "target#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject");
i.putExtra(Intent.EXTRA_TEXT , "body part");
try
{
startActivity(Intent.createChooser(i, "Sending Email..."));
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(MyActivity.this, "No Email clients",Toast.LENGTH_SHORT ).show();
}
This code will allow you to communicate via Gmail Server.