Android - How to open the email client directly

前端 未结 2 1605
忘了有多久
忘了有多久 2020-12-16 05:18

I want to open the default email client instead of showing the options. I tried but i am not getting please can anyone help me.

I used the following code:

         


        
2条回答
  •  半阙折子戏
    2020-12-16 06:00

    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 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)));
            }
    } 
    

提交回复
热议问题