2014-12-13 80 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。

相關問題