I am sort of new to android.
I am trying to send a msg via gmail and this is my code.
Intent intent = new Intent(Intent.ACTION_SENDTO);
String uriText;
uriText = "mailto:test#gmail.com?subject=Subject&body=this is test.";
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
intent.setData(uri);
startActivity(Intent.createChooser(intent, "Select mailer"));
It works. But, before sending the msg, it shows a selection box
and asks me to choose either gmail or email.
How can I skip the selection box ?
Any help would be so appreciated.. Thanks.
How can I skip the selection box ?
You don't. You allow the user to choose what application they wish to use to send the message. Some users do not use Gmail.
Related
I tried to search on Google but didn't find an appropriate answer.
I want to click a TextView and it will show a dialog that allows the user to choose optional email.
Any suggestion? Thanks in advance
Try this:
Intent intet = new Intent(Intent.ACTION_SEND);
intet.setType("message/rfc822");
intet.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(intet);
This will open up a dialog that contains a list of apps installed on the device that can send an email.
Hope this helps. :)
A better option is to use the following, it will only open the applications that provide mail facility and not all apps that can share data.
Intent emailIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "subject" + "&body=" + "body" + "&to=" + email_id);
emailIntent.setData(data);
startActivity(emailIntent);
"subject" is the subject of mail, "body" is the content of the mail, and "email_id" is the id of the receiver of the mail.
You can keep the subject , body and email_id empty if you want the user to fill in the spaces.
for open gmail app
try this code:
Intent gmail = new Intent(Intent.ACTION_VIEW);
gmail.setClassName("com.google.android.gm","com.google.android.gm.ConversationListActivity");
startActivity(gmail);
how to send a whatsapp message to a specific contact automatically?I have searched but it just opens the chat of that specific person but does not send the message automatically
Here is the code that am using:
private void openWhatsappContact(String number) {
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
I'm not sure you can send the message automatically, but try this to specify the message you want to send:
i.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
Reference:
https://www.whatsapp.com/faq/en/android/28000012
There is no direct way to do this because whatsapp does not offer an SDK interface.
You might have some luck with writing some accessibility automations or if you have root may be some xposed module.
This question already has answers here:
Send HTML mail using Android intent
(5 answers)
Closed 3 months ago.
I want to send email through my application. I need to send HTML based email just through G-Mail. I found following solutions that each of them has pros and cons.
1) Using Intent (Intent.ACTION_SEND). This is very simple way and I can see my body in HTML format but the problem is when I click on "Send email" button, so many applications like Facebook and Google+ pop up which are useless and I shouldn't show it in that list. This is its code:
String html = "<!DOCTYPE html><html><body>Visit W3Schools.com!" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"MY EMAIL ADDRESS"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(html));
startActivity(Intent.createChooser(intent, "Send email..."));
2) Using Intent (Intent.ACTION_SENDTO). This way Filters useless applications and shows me just mail clients. But it doesn't display my email in HTML format in gmail client. When i send the email some clients show the body in HTML format while others doesn't identify HTML and my link behaves like plain text. This code is like:
String html = "<!DOCTYPE html><html><body>Visit W3Schools.com!" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:MY EMAIL ADDRESS" + "?subject=subject here" + "&body=" + html;
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
3) Sending mail using JavaMail API which adds so much complexity to application and I didn't test it so far.
What is your suggestion? I need a way to have advantages of first and second ways. I need when user click on button it shows Gmail client and I can show him/her html content in body part of client.
any suggestion would be appreciated. Thanks
======================
Update
Something about code 2 is wrong. The code is like this:
String html = "<!DOCTYPE html><html><body>Visit W3Schools.com!" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:MY EMAIL ADDRESS" + "?subject=subject here" + "&body=" + Html.fromHtml(html);
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
Try the following -
Intent shareIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(body));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(shareIntent);
This will only present email applications.
If you want only one application to handle your intent then you need to remove Intent.createChooser(), rather jst use startActivity()---> it send the mail using default email client, if not set then will ask to do so... tat can be changed anytime
To get only email applications, use
Intent.setType("message/rfc822")
I am creating an app in which user can share "something" by clicking on a share button.
The steps to share "something" are:
On clicking the share button the contact list should open
By selecting a contact (with valid a email address) the data should be sent directly to the selected contact from the sender's default email address(Gmail) without popping up a window for selecting an email client like "Gmail", "Dropbox" etc..
I managed to get the email id of contact with the help of
http://mobile.tutsplus.com/tutorials/android/android-essentials-using-the-contact-picker/
but after selecting a contact I get a pop up for selecting an email client like "Gmail", "Dropbox" etc..
here is my code so far
if( email.length() != 0 )
{
Intent sharingIntent = new Intent(
android.content.Intent.ACTION_SEND );
sharingIntent.setType("message/rfc822");
String shareBody =
"Hey buddy listen to this station it is awesome\n"
+ mNowPlayingSong.mAudioUrl;
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"I liked this song" );
sharingIntent.putExtra(
android.content.Intent.EXTRA_TEXT, shareBody );
String emailAddressList[] = {email};
sharingIntent.putExtra(Intent.EXTRA_EMAIL, emailAddressList );
startActivity( sharingIntent );
You cannot send email silently with the default application. You can only create an intent that will call an activity and that will fill in all the fields.
Other possibility is to embed your own email client into yours application. In this case, if a user provides credentials then you'll have a possibility to send a email silently. To implement the second options check this:
Sending Email in Android using JavaMail API without using the default/built-in app
i want to choice a app to send email:only email app to send my email,i have read How to open Email program via Intents (but only an Email program) i used intent.setType("message/rfc822") ,it very well,but Bluetooth and email give me to choice,i want to remove Bluetooth,and want to Leave only email.can you tell me how to send email not to show Bluetooth to give mo choice;
edit: if i used Intent intent = new Intent(Intent.ACTION_SENDTO); the bluetooth is remove but add Text messages t0 give me choice.i also used
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
the bluetooth also remove but also add add Text messages t0 give me choice.is there i way to only email app to send email?