Android - Opening the email application?

后端 未结 4 1801
时光说笑
时光说笑 2021-02-01 13:47

I want to open the email application on my android app: The following code crashes Am I doing anything wrong? please provide code

Intent i = new Intent (Intent.A         


        
4条回答
  •  我在风中等你
    2021-02-01 14:20

    Prefer to use constants if available like for intent.type ClipDescription.MIMETYPE_TEXT_PLAIN

    Kotlin:

    val intent = Intent(Intent.ACTION_SEND)
    intent.type = ClipDescription.MIMETYPE_TEXT_PLAIN
    intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("emailId 1", "emailId 2"))
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject for email")
    intent.putExtra(android.content.Intent.EXTRA_TEXT, "Description for email")
    startActivity(Intent.createChooser(intent,"Send Email"))
    

    Java:

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"emailId 1", "emailId 2"});
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject for email");
    intent.putExtra(android.content.Intent.EXTRA_TEXT, "Description for email");
    startActivity(Intent.createChooser(intent,"Send Email"));
    

提交回复
热议问题