发送电子邮件时,我收到错误“没有应用程序可以执行此操作”

时间:2012-07-28 17:17:41

标签: android android-intent

这是代码,Everythin运行良好,除了没有应用程序可以执行此操作“错误..请告诉我代码中的错误。

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

            }}

5 个答案:

答案 0 :(得分: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();

通过点击我获取手机上安装的所有电子邮件应用程序。

答案 1 :(得分:1)

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

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

答案 2 :(得分:1)

删除startActivity()或startActivityForResult()

答案 3 :(得分: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);

答案 4 :(得分:0)

2我给你的建议:

1,在Google API目标模拟器中运行它或在设备中运行

2,在运行此应用之前首先登录您的电子邮件帐户:)

欢呼声