android - 发送电子邮件时出现错误“没有应用程序可以执行此操作”

标签 android android-intent

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

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

            }}

最佳答案

这对我有帮助:

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

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

关于android - 发送电子邮件时出现错误“没有应用程序可以执行此操作”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11703114/

相关文章:

java - Android sqlite - "No such table"而表存在

c# - 在 Xamarin Forms 中应该使用哪个包而不是 Android.Content 来获取类 Intent?

android - Intent 过滤器浏览器 android :pathPrefix url parameter

安卓通知 Intent.putExtra

android - 无法从 RecyclerView.OnScrollListener 调用 notifyItemInserted()

android - 如何深入链接到Android中的Amazon Shopping应用程序的产品页面?

android - Flutter Image_picker无法解析所有 Artifact 以进行配置

android - Firefox for Android 内容提供商?

android - 指定调用此应用的包名

Android 应用程序电子邮件附件无法在 Gmail 应用程序中通过