2014-12-13 200 views
0

我用这个在android中以编程方式发送电子邮件,但在Android 4.4.4中工作不好。有没有另一种方法来做到这一点?这是我的代码,谢谢。以编程方式发送邮件Android

Intent i = new Intent(Intent.ACTION_SEND); 
//i.setType("text/plain"); //use this line for testing in the emulator 
i.setType("message/rfc822") ; // use from live device 

i.putExtra(Intent.EXTRA_SUBJECT,"-my app-"); 
i.putExtra(Intent.EXTRA_TEXT,"Hello"); 
startActivity(Intent.createChooser(i, "Select your mail app")); 
+0

请详细解释**,完全而准确地说**,“不好”的意思。 – CommonsWare 2014-12-13 15:07:13

+0

对话框在屏幕上显示很大 – 2014-12-13 15:11:15

回答

0

我希望下面的代码将是有益的你..

protected void sendEmail() { 

     String[] recipients = {recipient.getText().toString()}; 
     Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); 

     // prompts email clients only 
     email.setType("message/rfc822"); 
     email.putExtra(Intent.EXTRA_EMAIL, recipients); 
     email.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString()); 
     email.putExtra(Intent.EXTRA_TEXT, body.getText().toString()); 
     try { 
     // the user can choose the email client 
     startActivity(Intent.createChooser(email, "Choose an email client from...")); 
     } catch (android.content.ActivityNotFoundException ex) { 
     Toast.makeText(MainActivity.this, "No email client installed.", 
       Toast.LENGTH_LONG).show(); 
     } 

    } 

上面的代码对我的作品! 享受!

+0

什么是收件人?谢谢 – 2014-12-13 15:01:46

+0

工作不好,屏幕上的对话框显示很大 – 2014-12-13 15:11:00

+0

Android 4.4.4适合我。我认为这应该是设备解决问题​​。 – 2014-12-13 15:14:15

1

对话框出现在屏幕

选择器窗口的大小取决于设备,而不是你在非常大的。设备上的所有应用程序的选择器窗口大小与触发选择器的大小相同,因此用户将希望看到具有一个选择器的设备上的“非常大”的选择器窗口。

如果您觉得选择器窗口的大小应该是您想要的,而不是您的用户期望的大小,那么您将需要创建自己的选择器。你可以使用PackageManagerqueryIntentActivities()来做到这一点,看看什么都响应你的Intent,并用它来填充你自己设计的选择器UI。

相关问题