Android - Opening the email application?

后端 未结 4 1816
时光说笑
时光说笑 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:16

    /* Create the Intent */
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    
    /* Fill it with Data */
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
    
    /* Send it off to the Activity-Chooser */
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    

    Try this, it is a bit more clear. Nonetheless intent for emails only works if you are using the application in a real phone, so if you are using the emulator, try it on a real phone.

提交回复
热议问题