電子郵件分享使用 android intent Text Only

這將觸發本機電子郵件客戶端以共享文字。

引數 :電子郵件地址,主題,正文。

程式碼示例:

你可以在任何需要的地方呼叫該函式 *(主要是在單擊偵聽器中),*如下所示

呼叫功能

shareEmail("sample@gmail.com", "Email sharing example", "This the sample demo to share the sample text through native email clients using Android Intent");

全域性功能

public void shareEmail(String to_email_id, String subject, String body) {
    // This function will open the email client installed in the device to share from your own app through intent.
    Intent sharingIntent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
    sharingIntent.setType("message/rfc822");

    /* All the below fields are optional. If not given simply opens the email client */
    // To email id
    sharingIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{to_email_id});
    // Subject that needs to appear while sharing
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    // Body of the mail content shared.
    sharingIntent.putExtra(Intent.EXTRA_TEXT, body);

    (mContext).startActivity(Intent.createChooser(sharingIntent, "Share content through email")

    );
  } // shareEmail