如何在点击按钮的Android Studio上发送邮件?

如何在点击按钮的Android Studio上发送邮件?,android,android-studio,email,android-intent,Android,Android Studio,Email,Android Intent,我想发送电子邮件,单击按钮时,我想查看基于电子邮件的应用程序列表。当我使用下面的源代码时,它会输出所有基于消息的应用程序,如图所示 Intent intent2 = new Intent(Intent.ACTION_SEND); intent2.setData(Uri.parse("mailto:")); intent2.setType("plain/text"); intent2.putExtra(Intent.EXTRA_EMAIL, new String[]{email}); startA

我想发送电子邮件,单击按钮时,我想查看基于电子邮件的应用程序列表。当我使用下面的源代码时,它会输出所有基于消息的应用程序,如图所示

Intent intent2 = new Intent(Intent.ACTION_SEND);
intent2.setData(Uri.parse("mailto:"));
intent2.setType("plain/text");
intent2.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
startActivity(intent2);
当我点击按钮时,这些应用程序就会显示出来

但我只想要基于电子邮件的应用程序,例如我应该更改什么才能获得这样的应用程序列表?

您可以使用此

 btnReport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String mailto = "mailto:useremail@gmail.com" +
                    "?cc=" +
                    "&subject=" + Uri.encode("your subject") +
                    "&body=" + Uri.encode("your mail body");
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
            emailIntent.setData(Uri.parse(mailto));

            try {
                startActivity(emailIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(context, "Error to open email app", Toast.LENGTH_SHORT).show();
            }
        }
    });
你可以用这个

 btnReport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String mailto = "mailto:useremail@gmail.com" +
                    "?cc=" +
                    "&subject=" + Uri.encode("your subject") +
                    "&body=" + Uri.encode("your mail body");
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
            emailIntent.setData(Uri.parse(mailto));

            try {
                startActivity(emailIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(context, "Error to open email app", Toast.LENGTH_SHORT).show();
            }
        }
    });

只需在你的onClicklistener中调用电子邮件意图

Intent email = new Intent(Intent.ACTION_SEND);  
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});  
email.putExtra(Intent.EXTRA_SUBJECT, subject);  
email.putExtra(Intent.EXTRA_TEXT, message);  

//need this to prompt`enter code here`s email client only  
email.setType("message/rfc822");  

startActivity(Intent.createChooser(email, "Choose an Email client :"));  

只需在你的onClicklistener中调用电子邮件意图

Intent email = new Intent(Intent.ACTION_SEND);  
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});  
email.putExtra(Intent.EXTRA_SUBJECT, subject);  
email.putExtra(Intent.EXTRA_TEXT, message);  

//need this to prompt`enter code here`s email client only  
email.setType("message/rfc822");  

startActivity(Intent.createChooser(email, "Choose an Email client :"));  

不使用Send可消除附件的使用。不使用Send可消除附件的使用。无更改,它还显示WhatsApp、电报、蓝牙应用无更改,它还显示WhatsApp、电报、蓝牙应用