Android - How to open the email client directly

元气小坏坏 提交于 2019-11-29 02:19:47

You can used the following code to open whatever intent you want eg gmail, facebook, email etc..Simple in the type as used in my code pass "gmail" if you want to open gmail, pass "face" if u want to open facebook

Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
intent.setType("text/html");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);

if (!resInfo.isEmpty())
{
    for (ResolveInfo info : resInfo) 
    {
    if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type)) 
    {
            intent.putExtra(android.content.Intent.EXTRA_TEXT, htmlBody);
            intent.setPackage(info.activityInfo.packageName);   
            startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_send_text)));
        }
} 
Vinay Wadhwa

Frame a String in the format String URI="mailto:?subject=" + subject + "&body=" + body;

and

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse(URI);
intent.setData(data);
startActivity(intent);

This will open up the default e-mail program selected by the user.

Linkify does it this way. Check out it's source code, if you like.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!