Send Email Intent

前端 未结 30 3286
忘掉有多难
忘掉有多难 2020-11-22 07:27
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(\"text/html\");
intent.putExtra(Intent.EXTRA_EMAIL, \"emailaddress@emailaddress.com\");
intent.putExtr         


        
相关标签:
30条回答
  • 2020-11-22 07:51

    If you want only the email clients you should use android.content.Intent.EXTRA_EMAIL with an array. Here goes an example:

    final Intent result = new Intent(android.content.Intent.ACTION_SEND);
    result.setType("plain/text");
    result.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient });
    result.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    result.putExtra(android.content.Intent.EXTRA_TEXT, body);
    
    0 讨论(0)
  • 2020-11-22 07:53

    Following Code worked for me!!

    import android.support.v4.app.ShareCompat;
        .
        .
        .
        .
    final Intent intent = ShareCompat.IntentBuilder
                            .from(activity)
                            .setType("application/txt")
                            .setSubject(subject)
                            .setText("Hii")
                            .setChooserTitle("Select One")
                            .createChooserIntent()
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
                            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    
    activity.startActivity(intent);
    
    0 讨论(0)
  • 2020-11-22 07:53

    This code is working in my device

    Intent mIntent = new Intent(Intent.ACTION_SENDTO);
    mIntent.setData(Uri.parse("mailto:"));
    mIntent.putExtra(Intent.EXTRA_EMAIL  , new String[] {"mahendrarajdhami@gmail.com"});
    mIntent.putExtra(Intent.EXTRA_SUBJECT, "");
    startActivity(Intent.createChooser(mIntent, "Send Email Using..."));
    
    0 讨论(0)
  • 2020-11-22 07:54

    in Kotlin if anyone is looking

    val emailArrray:Array<String> = arrayOf("travelagentsupport@kkk.com")
    val intent = Intent(Intent.ACTION_SENDTO)
    intent.data = Uri.parse("mailto:") // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, emailArrray)
    intent.putExtra(Intent.EXTRA_SUBJECT, "Inquire about travel agent")
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
    
    0 讨论(0)
  • 2020-11-22 07:57

    A late answer, although I figured out a solution which could help others:

    Java version

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.parse("mailto:abc@xyz.com"));
    startActivity(Intent.createChooser(emailIntent, "Send feedback"));
    

    Kotlin version

    val emailIntent = Intent(Intent.ACTION_SENDTO).apply { 
        data = Uri.parse("mailto:abc@xyz.com")
    }
    startActivity(Intent.createChooser(emailIntent, "Send feedback"))
    

    This was my output (only Gmail + Inbox suggested):

    I got this solution from the Android Developers site.

    0 讨论(0)
  • 2020-11-22 07:57

    None of these solutions were working for me. Here's a minimal solution that works on Lollipop. On my device, only Gmail and the native email apps appear in the resulting chooser list.

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                                    Uri.parse("mailto:" + Uri.encode(address)));
    
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
    startActivity(Intent.createChooser(emailIntent, "Send email via..."));
    
    0 讨论(0)
提交回复
热议问题