2

这是代码,除了没有应用程序可以执行此操作“错误之外,一切正常。请让我知道代码中的错误是什么。

 public void sends(View button) {   
        // Do click handling here  


        final EditText date = (EditText) findViewById(R.id.editText1);  
        String da = date.getText().toString();  

        final EditText phone = (EditText) findViewById(R.id.editText2);  
        String ph = phone.getText().toString();  

        final EditText nameplate = (EditText) findViewById(R.id.editText3);  
        String np = nameplate.getText().toString(); 

        final EditText issue = (EditText) findViewById(R.id.editText4);  
        String i = issue.getText().toString(); 

        StringBuilder s= new StringBuilder(100);
        s.append(da);
        s.append(". ");
        s.append(ph);
        s.append(". ");
        s.append(np);
        s.append(". ");
        s.append(i);

        String st=s.toString();




        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
        //emailIntent.setType("plain/text");
        //startActivity(emailIntent); 
        startActivity(Intent.createChooser(emailIntent, "Send your email in:"));

        Intent emailIntentt= new Intent(android.content.Intent.ACTION_SEND);  

        String aEmailList[] = { "shreyas.tallani@gmail.com" };  


        emailIntentt.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);  
        //emailIntentt.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);  
        //emailIntentt.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);  

        emailIntentt.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");  

        emailIntentt.setType("message/rfc822");  
        emailIntentt.putExtra(android.content.Intent.EXTRA_TEXT, st);




        startActivityForResult(emailIntentt, REQUEST_SEND_MAIL);
    } 
    public static final int REQUEST_SEND_MAIL = 1;

    public void onActivityResult(int requestCode, int resultCode, Intent data) {



        switch (requestCode) {
        case REQUEST_SEND_MAIL:
            // When the request to send mail returns
            if (resultCode == Activity.RESULT_OK) {
                Toast.makeText(this, "message successfully sent", Toast.LENGTH_SHORT).show();

            } else {
                Toast.makeText(this, "sorry", Toast.LENGTH_SHORT).show();
            }

            }}
4

5 回答 5

4

这帮助了我:

String email = person.getEmail();
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(Intent.EXTRA_SUBJECT, "Happy Birthday!");
intent.setData(Uri.parse("mailto:" + email));
context.startActivity(Intent.createChooser(intent, "Send e-mail to"));

关于 Uri.fromParts() 方法有很多答案,但经过数小时的头痛 Uri.parse();

通过单击我可以在手机上安装所有电子邮件应用程序。

于 2016-04-04T21:37:45.613 回答
1

我会说你的问题是emailIntentt.setType("message/rfc822");。将类型设置为"plain/text"

也不要启动两个活动,一个就足够了,只需使用选择器。

于 2012-07-28T18:31:41.620 回答
1

删除 startActivity() 或 startActivityForResult()

于 2013-03-01T12:04:28.440 回答
0

你有startActivity()startActivityForResult!您必须有一个。这就是为什么第一个意图被触发并且没有应用程序可以捕获它的原因。

试试这个:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);   
String aEmailList[] = { "shreyas.tallani@gmail.com" };  

emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");   
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, st);

startActivityForResult(emailIntent, REQUEST_SEND_MAIL);
于 2012-07-28T18:23:59.730 回答
0

我给你的 2 条建议:

1、在谷歌API目标模拟器中运行或在设备中运行

2,在你运行这个应用程序之前先登录你的电子邮件帐户:)

干杯

于 2012-07-30T10:55:09.833 回答