Opening an email client on clicking a button

前端 未结 6 1873
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 06:01

I am designing an app in which i need to open an email client on clicking a button. The email client should be opened with a pre-defined subject and \'to\' address. Is there

6条回答
  •  一个人的身影
    2020-12-13 06:37

    To show only email clients use this code:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.parse("mailto:recipient@example.com?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body));
    intent.setData(data);
    startActivity(intent);
    

    If you already chose default email client then it will launch it. Otherwise it will show a list of available email clients.

提交回复
热议问题