Android open mail client - android

How can I open mail client from my app, NOT SENDING EMAIL just open the inbox?
when I use
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:recipient#example.com?subject=" + "" + "&body=" + "");
intent.setData(data);
startActivity(intent);
It opens the send mail view, and I want to open the inbox.

From #CommonsWare answer
This is what worked for me:
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_EMAIL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Min SDK 15
startActivity(intent);

You can just use in your xml, like this:
android:autoLink="email"

Related

Open mail app via intent doesn't open chooser

I'm trying to open an mail application on Android via intent. The purpose is to have a button in the app that will open your mail inbox. However when I use:
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_EMAIL)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(Intent.createChooser(intent, "Email"))
It always opens gmail, while I also have Outlook installed. The only way I get to choose between the mail apps is when yo use the mailto. But I don't intent to send an email, so it is not desired to use that intent.
Doesn't Outlook support this Intent?
use the following snippet to open to outlook directly from a different app
context.startActivity(
Intent().apply {
action = Intent.ACTION_MAIN
addCategory(Intent.CATEGORY_LAUNCHER)
component = ComponentName(
outlookLaunchIntent?.component?.packageName,
outlookLaunchIntent?.component?.className
)
setPackage(outlookLaunchIntent.package)
}
)
com.microsoft.office.outlook is the package name for outlook
For sending it to all email clients use a uri like this
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
Ref:How to open Email program via Intents (but only an Email program)

Opening a WhatsApp chat with a specific contact by clicking on a button in my app (Kotlin)

How can I Open a Whatsapp chat with a specific contact by clicking on a button in my app?
That's the code I use. It opens WhatsApp and let me search the contact I want to send the message to, but it doesn't open the WhatsApp chat with the specific contact number I gave it to.
whatsappButton.setOnClickListener{
var con = itemView.context
val textToShare = "*כח אדם*"
val phoneNumber = blogPost.phone
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.type = "text/plain"
sendIntent.putExtra("jid", phoneNumber+"#s.whatsapp.net")
sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare)
val extra = sendIntent.extras
startActivity(con,sendIntent,extra)
}
If you want send a message to a specific contact from Contacts app, you should first require permission to access contacts, get the number and try with this:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("YOUR_PHONE_NUMBER")+"#s.whatsapp.net");
startActivity(sendIntent);
Ref: https://stackoverflow.com/a/40285262/2895571
Please check this answer here
Use the following bit of code:
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);
First option: using Uri to convert whatsapp web url into button:
open_whatsapp.setOnClickListener {
val url = "https://api.whatsapp.com/send?phone=XXXXXXXXXX"
val openWhatsappIntent = Intent(Intent.ACTION_VIEW)
openWhatsappInten.data = Uri.parse(url)
startActivity(openWhatsappInten)
}
Second option; this is used as a href in web development :
Tel: XXX XXXX XX
maybe you can add Html format into TextView (Html.fromHtml()) and enable links clickeable to open the whatsapp application.
if you want send message to particular contact in whatsapp , use below url and particular mobile no to the Intent(including Country code).
String url = "https://wa.me/";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url+mobile_no));
startActivity(browserIntent);

ShareActionProvider - send string with link

Couldn't find the answer to my problem, so here is my question:
I have an app storing debts and where i can send the debt info to anyone using ShareActionProvider in the actionbar. It all works fine, i can send a string via, let's say, whatsapp. So far, so good. I wanted to include a link to the app in the play store at the end of the message but couldn't find out how to do it.
Here the intent I'm sending via the ShareActionProvider
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message);
i.setType("text/plain");
How can i achieve to add something like this:
Don't forget to check out this
just append the link to the end.
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=" + getPackageName());
i.setType("text/plain");
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
i.setType("text/plain");

Pre-populated recipient in Android email?

I am making an application where the user will click on contact us section and it will open the built-in Gmail application and I have the code to pre-populate the subject and message body in the mail.
I want the code to pre-populate the "To: " section where we add the recipient.
That didn't work for me but this did
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?to="+emailaddress+"&subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
Hope this helps someone else out there
In the intent you use to populate the subject and message, add the following:
intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "youremail#domain.com" });
Check the documentation for EXTRA_EMAIL

How to send an attachment with the Email in android?

Can any body share any code snippet in order to send an attachment with an email using android
native client.
Thanks & Regards,
This is what I found,
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
i.setType("audio/amr");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + attachmentFilePath));
startActivity(i);

Categories

Resources